mirror of
https://github.com/WGDashboard/WGDashboard-PRW.git
synced 2026-08-04 06:52:58 +00:00
feat: configurable loglevel
This commit is contained in:
@@ -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, {}
|
||||
@@ -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
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -34,6 +34,4 @@ class utilities():
|
||||
|
||||
except Exception as err:
|
||||
log.critical('failed to create directory')
|
||||
return False
|
||||
|
||||
|
||||
return False
|
||||
Reference in New Issue
Block a user