mirror of
https://github.com/mynodebtc/mynode.git
synced 2024-11-11 16:09:16 +00:00
Improve logging
This commit is contained in:
parent
124b0eb334
commit
4956eadb82
|
@ -185,6 +185,7 @@ if ! skip_base_upgrades ; then
|
|||
rm -f /home/bitcoin/.mynode/lnbits_version
|
||||
rm -f /home/bitcoin/.mynode/pyblock_version
|
||||
rm -f /home/bitcoin/.mynode/ckbunker_version
|
||||
rm -f /home/bitcoin/.mynode/joininbox_version_latest
|
||||
|
||||
cd ~
|
||||
else
|
||||
|
|
|
@ -46,7 +46,7 @@ def api_get_bitcoin_info():
|
|||
b["difficulty"] = None
|
||||
data["recent_blocks"] = blocks
|
||||
|
||||
#app.logger.info("api_get_bitcoin_info data: "+json.dumps(data))
|
||||
#log_message("api_get_bitcoin_info data: "+json.dumps(data))
|
||||
return jsonify(data)
|
||||
|
||||
@mynode_api.route("/api/get_lightning_info")
|
||||
|
|
|
@ -6,7 +6,6 @@ import time
|
|||
import re
|
||||
import datetime
|
||||
import urllib
|
||||
from flask import current_app as app
|
||||
from threading import Timer
|
||||
from utilities import *
|
||||
from bitcoin_info import *
|
||||
|
@ -366,7 +365,7 @@ def lnd_get(path, timeout=10, params={}):
|
|||
headers = {"Grpc-Metadata-macaroon":macaroon}
|
||||
r = requests.get("https://localhost:"+LND_REST_PORT+"/v1"+path, verify=TLS_CERT_FILE,headers=headers, params=params, timeout=timeout)
|
||||
except Exception as e:
|
||||
app.logger.info("ERROR in lnd_get: "+str(e))
|
||||
log_message("ERROR in lnd_get: "+str(e))
|
||||
return {"error": str(e)}
|
||||
return r.json()
|
||||
|
||||
|
@ -376,7 +375,7 @@ def lnd_get_v2(path, timeout=10):
|
|||
headers = {'Grpc-Metadata-macaroon': macaroon}
|
||||
r = requests.get("https://localhost:"+LND_REST_PORT+"/v2"+path, verify=TLS_CERT_FILE, headers=headers, timeout=timeout)
|
||||
except Exception as e:
|
||||
app.logger.info("ERROR in lnd_get_v2: "+str(e))
|
||||
log_message("ERROR in lnd_get_v2: "+str(e))
|
||||
return {"error": str(e)}
|
||||
return r.json()
|
||||
|
||||
|
|
|
@ -747,6 +747,7 @@ def start_threads():
|
|||
global threads
|
||||
app.logger.info("STARTING THREADS")
|
||||
|
||||
|
||||
# Start threads
|
||||
btc_thread1 = BackgroundThread(update_bitcoin_main_info_thread, 60) # Restart after 60, thread manages timing
|
||||
btc_thread1.start()
|
||||
|
@ -760,7 +761,7 @@ def start_threads():
|
|||
lnd_thread = BackgroundThread(update_lnd_info_thread, 60)
|
||||
lnd_thread.start()
|
||||
threads.append(lnd_thread)
|
||||
price_thread = BackgroundThread(update_price_info_thread, 60*5) # 5 minutes
|
||||
price_thread = BackgroundThread(update_price_info_thread, 15) # 5 minutes
|
||||
price_thread.start()
|
||||
threads.append(price_thread)
|
||||
drive_thread = BackgroundThread(update_device_info, 60)
|
||||
|
@ -804,6 +805,8 @@ if __name__ == "__main__":
|
|||
signal.signal(signal.SIGTERM, on_shutdown)
|
||||
signal.signal(signal.SIGINT, on_shutdown)
|
||||
|
||||
set_logger(app.logger)
|
||||
|
||||
# Setup and start threads
|
||||
start_threads()
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ def get_latest_price():
|
|||
global price_data
|
||||
if len(price_data) > 0:
|
||||
return price_data[len(price_data) - 1]["price"]
|
||||
return "N/A"
|
||||
return "MISSING"
|
||||
|
||||
def get_price_diff_24hrs():
|
||||
global price_data
|
||||
|
@ -41,7 +41,9 @@ def update_price_info():
|
|||
data = json.loads(price_json_string)
|
||||
price = data["bpi"]["USD"]["rate_float"]
|
||||
|
||||
except:
|
||||
except Exception as e:
|
||||
log_message("update_price_info EXCEPTION: {}".format(str(e)))
|
||||
price = "ERR"
|
||||
pass
|
||||
|
||||
# Add latest price
|
||||
|
@ -50,6 +52,7 @@ def update_price_info():
|
|||
d["time"] = now
|
||||
d["price"] = price
|
||||
price_data.append(d)
|
||||
log_message("UPDATE PRICE {}".format(price))
|
||||
|
||||
# only keep 24 hours of updates
|
||||
while len(price_data) > 0:
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
from config import *
|
||||
from flask import Blueprint, render_template, session, abort, Markup, request, redirect, send_from_directory, url_for, flash
|
||||
from flask import current_app as app
|
||||
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
|
||||
from bitcoin import is_bitcoin_synced
|
||||
from bitcoin_info import using_bitcoin_custom_config
|
||||
|
|
|
@ -4,6 +4,7 @@ import sys
|
|||
import codecs
|
||||
import urllib
|
||||
|
||||
mynode_logger = None
|
||||
|
||||
#==================================
|
||||
# Python Info
|
||||
|
@ -61,6 +62,24 @@ def set_file_contents(filename, data):
|
|||
return False
|
||||
|
||||
|
||||
#==================================
|
||||
# Logging Functions
|
||||
#==================================
|
||||
def log_message(msg):
|
||||
# Logs to www log
|
||||
global mynode_logger
|
||||
if mynode_logger != None:
|
||||
mynode_logger.info(msg)
|
||||
|
||||
def set_logger(l):
|
||||
global mynode_logger
|
||||
mynode_logger = l
|
||||
|
||||
def get_logger():
|
||||
global mynode_logger
|
||||
return mynode_logger
|
||||
|
||||
|
||||
#==================================
|
||||
# Log functions (non-systemd based)
|
||||
#==================================
|
||||
|
|
Loading…
Reference in New Issue
Block a user