make loglevel adjustable in config or on CLI

This commit is contained in:
Jakob Ketterl 2022-11-29 20:23:39 +01:00
parent 90ed47a115
commit 975f5ffdf0
3 changed files with 12 additions and 7 deletions

View File

@ -1,6 +1,7 @@
[core] [core]
data_directory = /var/lib/openwebrx data_directory = /var/lib/openwebrx
temporary_directory = /tmp temporary_directory = /tmp
log_level = INFO
[web] [web]
port = 8073 port = 8073

View File

@ -1,7 +1,8 @@
import logging import logging
# the linter will complain about this, but the logging must be configured before importing all the other modules # the linter will complain about this, but the logging must be configured before importing all the other modules
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") # loglevel will be adjusted later, INFO is just for the startup
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
from http.server import HTTPServer from http.server import HTTPServer
@ -51,10 +52,6 @@ def main():
args = parser.parse_args() args = parser.parse_args()
# set loglevel to info for CLI commands
if args.module is not None and not args.debug:
logging.getLogger().setLevel(logging.INFO)
if args.version: if args.version:
print("OpenWebRX version {version}".format(version=openwebrx_version)) print("OpenWebRX version {version}".format(version=openwebrx_version))
return 0 return 0
@ -65,10 +62,10 @@ def main():
if args.module == "config": if args.module == "config":
return run_admin_action(configparser, args) return run_admin_action(configparser, args)
return start_receiver() return start_receiver(loglevel=logging.DEBUG if args.debug else None)
def start_receiver(): def start_receiver(loglevel=None):
print( print(
""" """
@ -91,6 +88,9 @@ Support and info: https://groups.io/g/openwebrx
Config.validateConfig() Config.validateConfig()
coreConfig = CoreConfig() coreConfig = CoreConfig()
# passed loglevel takes priority (used for the --debug argument)
logging.getLogger().setLevel(coreConfig.get_log_level() if loglevel is None else loglevel)
featureDetector = FeatureDetector() featureDetector = FeatureDetector()
failed = featureDetector.get_failed_requirements("core") failed = featureDetector.get_failed_requirements("core")
if failed: if failed:

View File

@ -34,6 +34,7 @@ class CoreConfig(object):
CoreConfig.checkDirectory(self.data_directory, "data_directory") CoreConfig.checkDirectory(self.data_directory, "data_directory")
self.temporary_directory = config.get("core", "temporary_directory") self.temporary_directory = config.get("core", "temporary_directory")
CoreConfig.checkDirectory(self.temporary_directory, "temporary_directory") CoreConfig.checkDirectory(self.temporary_directory, "temporary_directory")
self.log_level = config.get("core", "log_level")
self.web_port = config.getint("web", "port") self.web_port = config.getint("web", "port")
self.aprs_symbols_path = config.get("aprs", "symbols_path") self.aprs_symbols_path = config.get("aprs", "symbols_path")
@ -57,3 +58,6 @@ class CoreConfig(object):
def get_aprs_symbols_path(self): def get_aprs_symbols_path(self):
return self.aprs_symbols_path return self.aprs_symbols_path
def get_log_level(self):
return self.log_level