feat: configurable loglevel

This commit is contained in:
DaanSelen
2026-03-03 11:55:01 +01:00
parent 992baa2afc
commit 927d45c70f
7 changed files with 67 additions and 28 deletions
-14
View File
@@ -19,20 +19,14 @@ class checks():
]
try:
log.debug('searching predefined locations for the config file, takes first one.')
for path in possible_config_locations:
log.debug(f'testing path: {path}')
if os.path.exists(path):
log.debug(f'found a file at: {path}')
return True, path
else:
continue
return False, ''
except Exception as err:
log.error(f'error occured while searching for the config file: {err}')
return False, ''
@staticmethod
@@ -43,19 +37,13 @@ class checks():
config = cp.ConfigParser()
try:
log.debug('looking through the given config file')
config.read(config_path)
if len(config.sections()) == 0:
log.error('empty config, no sections')
return False, {}
for section in config.sections():
log.debug(f'checking integrity of section: {section}')
if len(config.items(section)) == 0:
log.warn(f'empty section: {section}, removing at runtime due to irrelevance')
config.remove_section(section)
config_dict = {}
@@ -66,9 +54,7 @@ class checks():
return True, config_dict
except cp.ParsingError as err:
log.error(f'error parsing the ini config file: {err}')
return False, {}
except Exception as err:
log.error(f'error occured while looking through the config file: {err}')
return False, {}
+2 -3
View File
@@ -4,10 +4,9 @@ import flask
def make_resp_obj(success: bool = True, message: str = "", data: dict = {}, http_code: int = 200) -> flask.wrappers.Response:
response = flask.make_response({
"status": success,
"message": message,
"status": success,
"data": data
}, http_code
)
}, http_code)
return response
+1 -1
View File
@@ -13,7 +13,7 @@ def auth_required():
if flask.request.method.lower() == "options":
return make_resp_obj(True, "", flask.jsonify({"status": True}), 200)
ok, config_server = utilities.filter_config(flask.current_app.wgdashboard_config, 'SERVER')
ok, config_server = utilities.filter_config(flask.current_app.wgd_config, 'SERVER')
if not ok:
return make_resp_obj(False, "Internal Error", {}, 500)
+37
View File
@@ -0,0 +1,37 @@
#!/bin/env python3
from logging.config import dictConfig
@staticmethod
def setup_logger(level: str = 'DEBUG') -> None:
dictConfig({
'version': 1,
'formatters': {
'default': {
'format': '[%(asctime)s] [%(levelname)s] in [%(module)s] %(message)s'
}
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'default',
'level': level
}
},
'root': {
'handlers': ['console'],
'level': level
},
'loggers': {
'werkzeug': { # make werkzeug logs match
'handlers': ['console'],
'level': level,
'propagate': False
},
'flask.app': { # make Flask internal logs match
'handlers': ['console'],
'level': level,
'propagate': False
}
}
})
+1 -3
View File
@@ -34,6 +34,4 @@ class utilities():
except Exception as err:
log.critical('failed to create directory')
return False
return False