From c825b5ebba2c6d5ae15a2624a8347e7defbcfd06 Mon Sep 17 00:00:00 2001 From: Gregory Ashton <gregory.ashton@ligo.org> Date: Wed, 12 Oct 2016 10:12:10 +0200 Subject: [PATCH] Fixes logging level Updates the logging initialisation so that, when called with -q flag, the log file is still written with INFO level log messages (only the console output is supressed). --- pyfstat.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pyfstat.py b/pyfstat.py index e1a8c6b..7c615c2 100755 --- a/pyfstat.py +++ b/pyfstat.py @@ -51,14 +51,17 @@ parser.add_argument('unittest_args', nargs='*') args, unknown = parser.parse_known_args() sys.argv[1:] = args.unittest_args + +logger = logging.getLogger() +logger.setLevel(logging.DEBUG) +stream_handler = logging.StreamHandler() if args.quite: - log_level = logging.WARNING + stream_handler.setLevel(logging.WARNING) else: - log_level = logging.DEBUG - -logging.basicConfig(level=log_level, - format='%(asctime)s %(levelname)-8s: %(message)s', - datefmt='%H:%M') + stream_handler.setLevel(logging.DEBUG) +stream_handler.setFormatter(logging.Formatter( + '%(asctime)s %(levelname)-8s: %(message)s', datefmt='%H:%M')) +logger.addHandler(stream_handler) def initializer(func): @@ -102,6 +105,7 @@ class BaseSearchClass(object): ' Log output to a log-file, requires class to have outdir and label ' logfilename = '{}/{}.log'.format(self.outdir, self.label) fh = logging.FileHandler(logfilename) + fh.setLevel(logging.INFO) fh.setFormatter(logging.Formatter( '%(asctime)s %(levelname)-8s: %(message)s', datefmt='%y-%m-%d %H:%M')) -- GitLab