From f9917614c94bc356d264aa07fb3d49c658e2a4d2 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Sun, 27 Oct 2013 15:37:04 +0100 Subject: [PATCH] clean and stable file logging; thanks to python-list for that --- bin/linspector | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/bin/linspector b/bin/linspector index 8546d5c..b0fa21f 100755 --- a/bin/linspector +++ b/bin/linspector @@ -20,7 +20,7 @@ along with this program. If not, see . """ -__version__ = "0.11.1" +__version__ = "0.11.2" __default_config__ = "./examples/minimal.json" import argparse @@ -79,13 +79,14 @@ def main(): if not path.exists(path.dirname(logfile)): os.makedirs(path.dirname(logfile)) - #logger.propagate = False - logging.basicConfig(level=args.loglevel) - #file_handler = logging.handlers.RotatingFileHandler(args.logfile, maxBytes=10485760, backupCount=4) - #file_formatter = logging.Formatter('%(asctime)s %(pathname)s %(module)s %(funcName)s %(lineno)d [%(levelname)s]: %(message)s') - #file_handler.setFormatter(file_formatter) - #file_handler.setLevel(level=args.loglevel) - #logger.addHandler(file_handler) + root_logger = logging.getLogger() + + formatter = logging.Formatter(logging.BASIC_FORMAT) + handler = logging.handlers.RotatingFileHandler(args.logfile, maxBytes=10485760, backupCount=4) + handler.setFormatter(formatter) + + root_logger.addHandler(handler) + root_logger.setLevel(args.loglevel) configParser = FullConfigParser() linConf, core = configParser.parse_config(args.config)