mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-18 22:54:23 +01:00
Updates pisad and __init__ to put together the log and config fixes
The setup of the logs and the parsing of the config file are closely related. The former need info from the later to be created, and needs to be setup only once per pisa instance. In the same way, the later need to only be loaded and validated once per pisa intance and contains info to setup the logs. Intead of setting up the logs in init and loading the config file in pisad, now both are dealt with in __init__
This commit is contained in:
@@ -1,27 +1,37 @@
|
||||
import logging
|
||||
|
||||
from pisa.utils.auth_proxy import AuthServiceProxy
|
||||
import os
|
||||
import pisa.conf as conf
|
||||
from common.tools import check_conf_fields, setup_logging, extend_paths
|
||||
from pisa.utils.auth_proxy import AuthServiceProxy
|
||||
|
||||
HOST = "localhost"
|
||||
PORT = 9814
|
||||
LOG_PREFIX = "pisa"
|
||||
|
||||
# Create the file logger
|
||||
f_logger = logging.getLogger("pisa_file_log")
|
||||
f_logger.setLevel(logging.INFO)
|
||||
# Load config fields
|
||||
conf_fields = {
|
||||
"BTC_RPC_USER": {"value": conf.BTC_RPC_USER, "type": str},
|
||||
"BTC_RPC_PASSWD": {"value": conf.BTC_RPC_PASSWD, "type": str},
|
||||
"BTC_RPC_HOST": {"value": conf.BTC_RPC_HOST, "type": str},
|
||||
"BTC_RPC_PORT": {"value": conf.BTC_RPC_PORT, "type": int},
|
||||
"BTC_NETWORK": {"value": conf.BTC_NETWORK, "type": str},
|
||||
"FEED_PROTOCOL": {"value": conf.FEED_PROTOCOL, "type": str},
|
||||
"FEED_ADDR": {"value": conf.FEED_ADDR, "type": str},
|
||||
"FEED_PORT": {"value": conf.FEED_PORT, "type": int},
|
||||
"DATA_FOLDER": {"value": conf.DATA_FOLDER, "type": str},
|
||||
"MAX_APPOINTMENTS": {"value": conf.MAX_APPOINTMENTS, "type": int},
|
||||
"EXPIRY_DELTA": {"value": conf.EXPIRY_DELTA, "type": int},
|
||||
"MIN_TO_SELF_DELAY": {"value": conf.MIN_TO_SELF_DELAY, "type": int},
|
||||
"SERVER_LOG_FILE": {"value": conf.SERVER_LOG_FILE, "type": str, "path": True},
|
||||
"PISA_SECRET_KEY": {"value": conf.PISA_SECRET_KEY, "type": str, "path": True},
|
||||
"DB_PATH": {"value": conf.DB_PATH, "type": str, "path": True},
|
||||
}
|
||||
|
||||
fh = logging.FileHandler(conf.SERVER_LOG_FILE)
|
||||
fh.setLevel(logging.INFO)
|
||||
fh_formatter = logging.Formatter("%(message)s")
|
||||
fh.setFormatter(fh_formatter)
|
||||
f_logger.addHandler(fh)
|
||||
# Expand user (~) if found and check fields are correct
|
||||
conf_fields["DATA_FOLDER"]["value"] = os.path.expanduser(conf_fields["DATA_FOLDER"]["value"])
|
||||
# Extend relative paths
|
||||
conf_fields = extend_paths(conf_fields["DATA_FOLDER"]["value"], conf_fields)
|
||||
|
||||
# Create the console logger
|
||||
c_logger = logging.getLogger("pisa_console_log")
|
||||
c_logger.setLevel(logging.INFO)
|
||||
# Sanity check fields and build config dictionary
|
||||
config = check_conf_fields(conf_fields)
|
||||
|
||||
ch = logging.StreamHandler()
|
||||
ch.setLevel(logging.INFO)
|
||||
ch_formatter = logging.Formatter("%(message)s.", "%Y-%m-%d %H:%M:%S")
|
||||
ch.setFormatter(ch_formatter)
|
||||
c_logger.addHandler(ch)
|
||||
setup_logging(config.get("SERVER_LOG_FILE"), LOG_PREFIX)
|
||||
|
||||
Reference in New Issue
Block a user