From ceb1ed7fac0d5d5d6b52ed8c84e2ff6d1da20b0f Mon Sep 17 00:00:00 2001 From: Riccardo Murri Date: Thu, 4 Jan 2018 20:35:04 +0100 Subject: [PATCH] Make function `configure_logger` a bit more readable. --- gc3libs/__init__.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gc3libs/__init__.py b/gc3libs/__init__.py index 8c48842b..3d9f39e1 100755 --- a/gc3libs/__init__.py +++ b/gc3libs/__init__.py @@ -1,6 +1,6 @@ #! /usr/bin/env python # -# Copyright (C) 2009-2016 S3IT, Zentrale Informatik, University of Zurich. All rights reserved. +# Copyright (C) 2009-2018 University of Zurich. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by @@ -152,15 +152,8 @@ def configure_logger( used for more advanced configuration; if it does not exist, then a sample one is created. """ - if name is None: - name = os.path.basename(sys.argv[0]) - log_conf = os.path.join(Default.RCDIR, name + '.log.conf') logging.basicConfig(level=level, format=format, datefmt=datefmt) - deploy_configuration_file(log_conf, "logging.conf.example") - logging.config.fileConfig(log_conf, { - 'RCDIR': Default.RCDIR, - 'HOMEDIR': os.path.expandvars('$HOME'), - }) + _load_logging_configuration_file(name) log = logging.getLogger("gc3.gc3libs") log.setLevel(level) log.propagate = 1 @@ -176,6 +169,17 @@ def configure_logger( except ImportError as err: log.warning("Could not import `coloredlogs` module: %s", err) +def _load_logging_configuration_file(name): + if name is None: + name = os.path.basename(sys.argv[0]) + log_conf = os.path.join(Default.RCDIR, name + '.log.conf') + deploy_configuration_file(log_conf, "logging.conf.example") + logging.config.fileConfig(log_conf, { + 'RCDIR': Default.RCDIR, + 'HOMEDIR': os.path.expandvars('$HOME'), + }) + return log_conf + UNIGNORE_ERRORS = set(os.environ.get('GC3PIE_NO_CATCH_ERRORS', '').split(',')) if 'ALL' in UNIGNORE_ERRORS: