Skip to content

Commit

Permalink
transfer changes from fedot (aimclub#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
maypink authored Feb 21, 2023
1 parent 1d6be04 commit 74d23b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions golem/core/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def reset_logging_level(self, logging_level: int):
self.logger.setLevel(logging_level)
for handler in self.handlers:
handler.setLevel(logging_level)
for adapter in self.__log_adapters.values():
adapter.logging_level = logging_level

def get_adapter(self, prefix: str) -> 'LoggerAdapter':
""" Get adapter to pass contextual information to log messages
Expand Down
23 changes: 23 additions & 0 deletions test/unit/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,26 @@ def test_multiple_adapters_with_one_prefix():

assert f'prefix_1 - {info_1}' in content
assert f'prefix_1 - {info_2}' in content


def test_reset_logging_level():
""" Checks that after resetting logging level it's also been reset in already initialized adapters. """
log = Log()
c = default_log('logger_1')
c.info('test_message_1') # should be shown since logging level is info by default
log.reset_logging_level(50)

b = default_log('logger_2')
b.message('test_message_2') # shouldn't be shown since logging level is critical now
c.message('test_message_3') # shouldn't be shown since logging level is critical now

log.reset_logging_level(20)
b.message('test_message_4') # should be shown since logging level is info now
c.message('test_message_5') # should be shown since logging level is info now

content = ''
if Path(DEFAULT_LOG_PATH).exists():
content = Path(DEFAULT_LOG_PATH).read_text()

assert (lambda message: message in content, ['test_message_1', 'test_message_4', 'test_message_5'])
assert (lambda message: message not in content, ['test_message_2', 'test_message_3'])

0 comments on commit 74d23b4

Please sign in to comment.