From f1b2a95d1049d732127ef21dd51d1d885440dbf6 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 25 May 2018 10:22:07 +0200 Subject: [PATCH] fix logging: do not create a 'ignored' file when using a console --- sfa/util/sfalogging.py | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/sfa/util/sfalogging.py b/sfa/util/sfalogging.py index e4b37c8a..5a9745cf 100644 --- a/sfa/util/sfalogging.py +++ b/sfa/util/sfalogging.py @@ -140,7 +140,7 @@ def logging_config(context): print("Cannot configure logging - exiting") exit(1) - return { + config = { 'version': 1, # IMPORTANT: we may be imported by something else, so: 'disable_existing_loggers': False, @@ -151,23 +151,9 @@ def logging_config(context): '%(filename)s:%(lineno)d %(message)s'), }, }, + # fill in later with just the one needed + # otherwise a dummy 'ignored' file gets created 'handlers': { - 'file': { - 'filename': filename, - 'level': level, - 'formatter': 'standard', - 'class': 'logging.handlers.TimedRotatingFileHandler', - # every monday and during 3 months - 'when': 'w0', - 'interval': 1, - 'backupCount': 12, - - }, - 'stdout': { - 'level': level, - 'formatter': 'standard', - 'class': 'logging.StreamHandler', - }, }, 'loggers': { 'sfa': { @@ -177,6 +163,24 @@ def logging_config(context): }, }, } + if handlername == 'stdout': + config['handlers']['stdout'] = { + 'level': level, + 'formatter': 'standard', + 'class': 'logging.StreamHandler', + } + else: + config['handlers']['file'] = { + 'filename': filename, + 'level': level, + 'formatter': 'standard', + 'class': 'logging.handlers.TimedRotatingFileHandler', + # every monday and during 3 months + 'when': 'w0', + 'interval': 1, + 'backupCount': 12, + } + return config logger = logging.getLogger('sfa') -- 2.43.0