X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Fsfalogging.py;h=5a9745cfb782e522bf35e47a2861f031bf0aa518;hb=052e281f8c79237b6759cbb259407f071adda1cc;hp=a8f88f5cc445ed46ed97611cb17bfc2534a988f2;hpb=00440a7c7e509301cb49db90ff15abc0f479aaf3;p=sfa.git diff --git a/sfa/util/sfalogging.py b/sfa/util/sfalogging.py index a8f88f5c..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,19 +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, - # not using RotatingFileHandler for this first version - 'class': 'logging.FileHandler', - 'formatter': 'standard', - }, - 'stdout': { - 'level': level, - 'class': 'logging.StreamHandler', - 'formatter': 'standard', - }, }, 'loggers': { 'sfa': { @@ -173,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')