diff --git a/plio/utils/log.py b/plio/utils/log.py index 0f8a2dec8b710ef70f5763be63061d0c0f7bea24..74721b8c7e2cf1ed8e71d44ee117c0ec319b5143 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 2cc848cceb09f78dcc5462ca13290af7de8c5840..5df02d77f338ce119a7b1973e1f78b9728686634 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)