X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Fsfalogging.py;h=fd1cabfef88170a8e11acf46e9e4ea807f7b4d4b;hb=4a9e6751f9f396f463932133b9d62fc925a99ef6;hp=e4b37c8adc976c6fdbf48c3f2f18f137f73223e4;hpb=479fe75aba4509060c663c0025dac7398269f7ff;p=sfa.git diff --git a/sfa/util/sfalogging.py b/sfa/util/sfalogging.py index e4b37c8a..fd1cabfe 100644 --- a/sfa/util/sfalogging.py +++ b/sfa/util/sfalogging.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 """ A reroutable logger that can handle deep tracebacks @@ -34,7 +34,7 @@ Implementation: # pylint: disable=c0111, c0103, w1201 -from __future__ import print_function + import os import os.path @@ -123,7 +123,7 @@ def logging_config(context): if context == 'server': handlername = 'file' filename = '/var/log/sfa.log' - level = 'INFO' + level = 'DEBUG' elif context == 'import': handlername = 'file' filename = '/var/log/sfa-import.log' @@ -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')