From 7a18939171f91f401e9cbd3287c16df56d30d387 Mon Sep 17 00:00:00 2001 From: nucleogenic Date: Mon, 1 Aug 2022 01:02:14 +0100 Subject: [PATCH] Add support for --log-level argument to web UI (#781) Increase verbosity of web UI log format Add critical to supported log levels for completeness --- python/web/src/web.py | 18 ++++++++++++++++-- python/web/start.sh | 5 ++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/python/web/src/web.py b/python/web/src/web.py index 3fbde85b..d5eb8848 100644 --- a/python/web/src/web.py +++ b/python/web/src/web.py @@ -2,6 +2,7 @@ Module for the Flask app rendering and endpoints """ +import sys import logging import argparse from pathlib import Path @@ -1028,14 +1029,23 @@ if __name__ == "__main__": default="localhost", action="store", help="RaSCSI host. Default: localhost", - ) + ) parser.add_argument( "--rascsi-port", type=int, default=6868, action="store", help="RaSCSI port. Default: 6868", - ) + ) + parser.add_argument( + "--log-level", + type=str, + default="warning", + action="store", + help="Log level for Web UI. Default: warning", + choices=["debug", "info", "warning", "error", "critical"], + ) + arguments = parser.parse_args() APP.config["TOKEN"] = arguments.password @@ -1047,5 +1057,9 @@ if __name__ == "__main__": if Path(f"{CFG_DIR}/{DEFAULT_CONFIG}").is_file(): file_cmd.read_config(DEFAULT_CONFIG) + logging.basicConfig(stream=sys.stdout, + format="%(asctime)s %(levelname)s %(filename)s:%(lineno)s %(message)s", + level=arguments.log_level.upper()) + print("Serving rascsi-web...") bjoern.run(APP, "0.0.0.0", arguments.port) diff --git a/python/web/start.sh b/python/web/start.sh index ae950730..a2013a7a 100755 --- a/python/web/start.sh +++ b/python/web/start.sh @@ -102,6 +102,9 @@ while [ "$1" != "" ]; do -o | --rascsi-port) ARG_RASCSI_PORT="--rascsi-port $VALUE" ;; + -l | --log-level) + ARG_LOG_LEVEL="--log-level $VALUE" + ;; *) echo "ERROR: unknown parameter \"$PARAM\"" exit 1 @@ -114,4 +117,4 @@ PYTHON_COMMON_PATH=$(dirname $PWD)/common/src echo "Starting web server for RaSCSI Web Interface..." export PYTHONPATH=$PWD/src:${PYTHON_COMMON_PATH} cd src -python3 web.py ${ARG_PORT} ${ARG_PASSWORD} ${ARG_RASCSI_HOST} ${ARG_RASCSI_PORT} +python3 web.py ${ARG_PORT} ${ARG_PASSWORD} ${ARG_RASCSI_HOST} ${ARG_RASCSI_PORT} ${ARG_LOG_LEVEL}