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
+5 -3
View File
@@ -7,19 +7,21 @@ peer_mtu = 1420
peer_keep_alive = 21
[Server]
app_port = 10086
hostname = 0.0.0.0
port = 10086
debug_enabled = true
wg_conf_path = /etc/wireguard
awg_conf_path = /etc/amnezia/amneziawg
app_prefix =
app_ip = 0.0.0.0
auth_req = true
version = v4.3.2
version = v5.0.0
dashboard_refresh_interval = 60000
dashboard_peer_list_display = grid
dashboard_sort = status
dashboard_theme = dark
wgdashboard_apikey = false
dashboard_language = en-US
log_level = DEBUG
[Account]
username = admin
+21 -4
View File
@@ -1,6 +1,7 @@
#!/bin/env python3
import logging as log
from logging.config import dictConfig
import flask
import json
@@ -8,29 +9,45 @@ import os
from modules.config.reader import reader
from modules.database.database import database
from modules.utilities.utilities import utilities as util
from modules.utilities.logger import setup_logger
from modules.routes.routes import routes
if __name__ == '__main__':
log.basicConfig(level=log.DEBUG)
# Read the config file (ini)
ok, config_contents = reader.read_config()
if not ok:
exit(1)
found, config_server = util.filter_config(config_contents, 'SERVER')
# Configure the loglevel of WGDashboard
wanted_loglevel = config_server.get('log_level', 'DEBUG').upper()
setup_logger(wanted_loglevel)
# Get the database configuration from thee config
found, config_database = util.filter_config(config_contents, 'DATABASE')
if not found:
exit(1)
# Make the engine and create the infrastructure
ok, engine, session = database.create_session(config_database)
ok = database.ensure_contents(engine)
# Configure the Flask app
app = flask.Flask("WGDashboard", template_folder=os.path.abspath("./static/dist/WGDashboardAdmin"))
app.register_blueprint(routes)
app.wgdashboard_config = config_contents
app.wgd_config = config_contents
app.engine = engine
app.db_session = session
app.run(debug=True, use_reloader=False)
debug_enabled = config_server.get('debug_enabled', False)
hostname = config_server.get('hostname', '0.0.0.0')
port = config_server.get('port', '10086')
app.run(
debug=debug_enabled,
host=hostname,
port=port,
use_reloader=False)
-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
}
}
})
-2
View File
@@ -35,5 +35,3 @@ class utilities():
except Exception as err:
log.critical('failed to create directory')
return False