[logging] Enabled overriding logger config by user config
This commit is contained in:
parent
f1d973b446
commit
c6c41adb02
|
@ -41,17 +41,21 @@ def read_configuration(test_config):
|
||||||
update_dict(config, test_config)
|
update_dict(config, test_config)
|
||||||
|
|
||||||
|
|
||||||
def configure_app(app, test_config=None):
|
def configure_logger():
|
||||||
global config
|
global config
|
||||||
read_configuration(test_config)
|
# Read default config
|
||||||
|
|
||||||
# Always enable this builtin plugins!
|
|
||||||
update_dict(config, {"auth": {"enabled": True}, "roles": {"enabled": True}, "users": {"enabled": True}})
|
|
||||||
|
|
||||||
logger_config = toml.load(_module_path / "logging.toml")
|
logger_config = toml.load(_module_path / "logging.toml")
|
||||||
|
|
||||||
if "LOGGING" in config:
|
if "LOGGING" in config:
|
||||||
|
# Override with user config
|
||||||
|
update_dict(logger_config, config.get("LOGGING"))
|
||||||
|
# Check for shortcuts
|
||||||
if "level" in config["LOGGING"]:
|
if "level" in config["LOGGING"]:
|
||||||
logger_config["loggers"]["flaschengeist"] = {"level": config["LOGGING"]["level"]}
|
logger_config["loggers"]["flaschengeist"] = {"level": config["LOGGING"]["level"]}
|
||||||
|
logger_config["handlers"]["console"]["level"] = config["LOGGING"]["level"]
|
||||||
|
logger_config["handlers"]["file"]["level"] = config["LOGGING"]["level"]
|
||||||
|
if not config["LOGGING"].get("console", True):
|
||||||
|
logger_config["handlers"]["console"]["level"] = "CRITICAL"
|
||||||
if "file" in config["LOGGING"]:
|
if "file" in config["LOGGING"]:
|
||||||
logger_config["root"]["handlers"].append("file")
|
logger_config["root"]["handlers"].append("file")
|
||||||
logger_config["handlers"]["file"]["filename"] = config["LOGGING"]["file"]
|
logger_config["handlers"]["file"]["filename"] = config["LOGGING"]["file"]
|
||||||
|
@ -59,6 +63,14 @@ def configure_app(app, test_config=None):
|
||||||
path.parent.mkdir(parents=True, exist_ok=True)
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
logging.config.dictConfig(logger_config)
|
logging.config.dictConfig(logger_config)
|
||||||
|
|
||||||
|
|
||||||
|
def configure_app(app, test_config=None):
|
||||||
|
global config
|
||||||
|
read_configuration(test_config)
|
||||||
|
|
||||||
|
# Always enable this builtin plugins!
|
||||||
|
update_dict(config, {"auth": {"enabled": True}, "roles": {"enabled": True}, "users": {"enabled": True}})
|
||||||
|
|
||||||
if "secret_key" not in config["FLASCHENGEIST"]:
|
if "secret_key" not in config["FLASCHENGEIST"]:
|
||||||
logger.warning("No secret key was configured, please configure one for production systems!")
|
logger.warning("No secret key was configured, please configure one for production systems!")
|
||||||
app.config["SECRET_KEY"] = "0a657b97ef546da90b2db91862ad4e29"
|
app.config["SECRET_KEY"] = "0a657b97ef546da90b2db91862ad4e29"
|
||||||
|
|
Loading…
Reference in New Issue