Skip to content

Commit

Permalink
add FastLogger.is_active() method
Browse files Browse the repository at this point in the history
  • Loading branch information
artgoldberg committed Dec 26, 2019
1 parent 2a709c1 commit 87a4e8f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions de_sim/utilities.py
Expand Up @@ -94,6 +94,8 @@ def __init__(self, logger, level_used):
level_used (:obj:`str`): a logging level, as used in :obj:`logging2.LogLevel`:
"""
self.active = FastLogger.active_logger(logger, level_used)
if self.active:
print(f'FastLogger {logger.name} IS active at {level_used}')
self.method = getattr(logger, level_used)
self.logger = logger

Expand All @@ -120,6 +122,14 @@ def active_logger(logger, level_used):
active = True
return active

def is_active(self):
""" Get the cached active state of this logger
Returns:
:obj:`bool`: whether this logger is active
"""
return self.active

def get_level(self):
""" Get the level of this logger
Expand All @@ -140,4 +150,5 @@ def fast_log(self, msg, **kwargs):
kwargs (:obj:`dict`): other logging arguments
"""
if self.active:
print(f'logging: {self.logger.name}')
self.method(msg, **kwargs)
4 changes: 4 additions & 0 deletions tests/test_utilities.py
Expand Up @@ -94,6 +94,10 @@ def test_active_logger(self):
with self.assertRaises(ValueError):
FastLogger(self.fixture_logger, 'not a level')

def test_is_active(self):
fast_logger = FastLogger(self.fixture_logger, self.fixture_level.name)
self.assertTrue(fast_logger.is_active())

def test_get_level(self):
for log_level in LogLevel:
handler = StdOutHandler(name="handler_{}".format(log_level), level=log_level)
Expand Down

0 comments on commit 87a4e8f

Please sign in to comment.