Skip to content
Snippets Groups Projects
Commit 3a7860ef authored by jlaura's avatar jlaura Committed by Jason R Laura
Browse files

Fixes regression in logging.

parent 1ab927eb
No related branches found
No related tags found
No related merge requests found
...@@ -5,39 +5,38 @@ import logging.config ...@@ -5,39 +5,38 @@ import logging.config
from ..examples import get_path from ..examples import get_path
def setup_logging(default_path=get_path('logging.json'), def setup_logging(path=get_path('logging.json'),
default_level='INFO', level='INFO',
env_key='LOG_CFG'): env_key='LOG_CFG'):
""" """
Read a log configuration file, written in JSON Read a log configuration file, written in JSON
Parameters Parameters
---------- ----------
default_path : string path : string
The path to the logging configuration file The path to the logging configuration file
default_level : object level : object
The logger level at which to report The logger level at which to report
env_key : str env_key : str
A potential environment variable where the user defaults logs A potential environment variable where the user defaults logs
""" """
path = default_path
value = os.getenv(env_key, None) value = os.getenv(env_key, None)
if value: if value:
path = value path = value
default_level = getattr(logging, default_level.upper()) print(level)
level = getattr(logging, level.upper())
print(level)
if os.path.exists(path): if os.path.exists(path):
logtype = os.path.splitext(os.path.basename(path))[1] logtype = os.path.splitext(os.path.basename(path))[1]
with open(path, 'rt') as f: with open(path, 'rt') as f:
if logtype == '.json': if logtype == '.json':
config = json.load(f, parse_float=True, config = json.load(f)
parse_int=True)
elif logtype == '.yaml': elif logtype == '.yaml':
import yaml import yaml
config = yaml.load(f.read()) config = yaml.load(f.read())
logging.config.dictConfig(config) logging.config.dictConfig(config)
else: else:
logging.basicConfig(level=default_level) logging.basicConfig(level=level)
logger = logging.getLogger() logger = logging.getLogger()
logger.setLevel(default_level) logger.setLevel(level)
\ No newline at end of file \ No newline at end of file
...@@ -12,17 +12,17 @@ class TestLog(unittest.TestCase): ...@@ -12,17 +12,17 @@ class TestLog(unittest.TestCase):
pass pass
def test_setup_json(self): 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__) logger = logging.getLogger(__name__)
self.assertEqual(logger.root.level, logging.DEBUG) self.assertEqual(logger.root.level, logging.DEBUG)
def test_setup_yaml(self): 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__) logger = logging.getLogger(__name__)
self.assertEqual(logger.root.level, logging.DEBUG) self.assertEqual(logger.root.level, logging.DEBUG)
def test_setup(self): def test_setup(self):
log.setup_logging() log.setup_logging(path='')
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
self.assertEqual(logger.root.level, logging.INFO) self.assertEqual(logger.root.level, logging.INFO)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment