From 3a7860ef22a11d4e7593d45e75ee1c18ee3dfb3c Mon Sep 17 00:00:00 2001 From: jlaura <jlaura@asu.edu> Date: Tue, 19 Jul 2016 19:36:44 -0700 Subject: [PATCH] Fixes regression in logging. --- plio/utils/log.py | 21 ++++++++++----------- plio/utils/tests/test_log.py | 6 +++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/plio/utils/log.py b/plio/utils/log.py index 0f8a2de..74721b8 100644 --- a/plio/utils/log.py +++ b/plio/utils/log.py @@ -5,39 +5,38 @@ import logging.config from ..examples import get_path -def setup_logging(default_path=get_path('logging.json'), - default_level='INFO', +def setup_logging(path=get_path('logging.json'), + level='INFO', env_key='LOG_CFG'): """ Read a log configuration file, written in JSON Parameters ---------- - default_path : string + path : string The path to the logging configuration file - default_level : object + level : object The logger level at which to report env_key : str A potential environment variable where the user defaults logs """ - - path = default_path value = os.getenv(env_key, None) if value: path = value - default_level = getattr(logging, default_level.upper()) + print(level) + level = getattr(logging, level.upper()) + print(level) if os.path.exists(path): logtype = os.path.splitext(os.path.basename(path))[1] with open(path, 'rt') as f: if logtype == '.json': - config = json.load(f, parse_float=True, - parse_int=True) + config = json.load(f) elif logtype == '.yaml': import yaml config = yaml.load(f.read()) logging.config.dictConfig(config) else: - logging.basicConfig(level=default_level) + logging.basicConfig(level=level) logger = logging.getLogger() - logger.setLevel(default_level) \ No newline at end of file + logger.setLevel(level) \ No newline at end of file diff --git a/plio/utils/tests/test_log.py b/plio/utils/tests/test_log.py index 2cc848c..5df02d7 100644 --- a/plio/utils/tests/test_log.py +++ b/plio/utils/tests/test_log.py @@ -12,17 +12,17 @@ class TestLog(unittest.TestCase): pass def test_setup_json(self): - log.setup_logging(default_path = get_path('logging.json')) + log.setup_logging(path=get_path('logging.json')) logger = logging.getLogger(__name__) self.assertEqual(logger.root.level, logging.DEBUG) def test_setup_yaml(self): - log.setup_logging(default_path=get_path('logging.yaml')) + log.setup_logging(path=get_path('logging.yaml')) logger = logging.getLogger(__name__) self.assertEqual(logger.root.level, logging.DEBUG) def test_setup(self): - log.setup_logging() + log.setup_logging(path='') logger = logging.getLogger(__name__) self.assertEqual(logger.root.level, logging.INFO) -- GitLab