From f9de5e61c4af444660dc2ae2ca1216b39a794323 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 15 May 2020 10:58:25 +0000 Subject: [PATCH] python: Correctly set log level for root logger Signed-off-by: Michael Tremer --- src/python/location-downloader.in | 2 +- src/python/location-exporter.in | 2 +- src/python/location-importer.in | 2 +- src/python/location-query.in | 4 ++++ src/python/logger.py | 8 +++++++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/python/location-downloader.in b/src/python/location-downloader.in index 2d38136..f1d38f1 100644 --- a/src/python/location-downloader.in +++ b/src/python/location-downloader.in @@ -247,7 +247,7 @@ class CLI(object): # Enable debug logging if args.debug: - log.setLevel(logging.DEBUG) + location.logger.set_level(logging.DEBUG) # Print usage if no action was given if not "func" in args: diff --git a/src/python/location-exporter.in b/src/python/location-exporter.in index 3e53d41..634b862 100644 --- a/src/python/location-exporter.in +++ b/src/python/location-exporter.in @@ -224,7 +224,7 @@ class CLI(object): # Enable debug logging if args.debug: - log.setLevel(logging.DEBUG) + location.logger.set_level(logging.DEBUG) return args diff --git a/src/python/location-importer.in b/src/python/location-importer.in index fe7c0b1..45cacad 100644 --- a/src/python/location-importer.in +++ b/src/python/location-importer.in @@ -93,7 +93,7 @@ class CLI(object): # Enable debug logging if args.debug: - log.setLevel(logging.DEBUG) + location.logger.set_level(logging.DEBUG) # Print usage if no action was given if not "func" in args: diff --git a/src/python/location-query.in b/src/python/location-query.in index fb695b0..85d1cbf 100644 --- a/src/python/location-query.in +++ b/src/python/location-query.in @@ -204,6 +204,10 @@ class CLI(object): args = parser.parse_args() + # Enable debug logging + if args.debug: + location.logger.set_level(logging.DEBUG) + # Print usage if no action was given if not "func" in args: parser.print_usage() diff --git a/src/python/logger.py b/src/python/logger.py index 18d8123..0bdf9ec 100644 --- a/src/python/logger.py +++ b/src/python/logger.py @@ -22,7 +22,7 @@ import logging.handlers # Initialise root logger log = logging.getLogger("location") -log.setLevel(logging.DEBUG) +log.setLevel(logging.INFO) # Log to console handler = logging.StreamHandler() @@ -38,3 +38,9 @@ log.addHandler(handler) # Format syslog messages formatter = logging.Formatter("%(message)s") handler.setFormatter(formatter) + +def set_level(level): + """ + Sets the log level for the root logger + """ + log.setLevel(level) -- 2.39.2