Skip to content

Commit 900d66e

Browse files
fix(2337): btlogging setLevel
1 parent 313521d commit 900d66e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

bittensor/utils/btlogging/loggingmachine.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,10 @@ def get_level(self) -> int:
582582
"""Returns Logging level."""
583583
return self._logger.level
584584

585+
def setLevel(self, level):
586+
"""Set the specified level on the underlying logger."""
587+
self._logger.setLevel(level)
588+
585589
def check_config(self, config: "Config"):
586590
assert config.logging
587591

tests/unit_tests/test_logging.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,25 @@ def test_all_log_levels_output(logging_machine, caplog):
212212
def test_concat(msg, prefix, suffix, expected_result):
213213
"""Test different options of message concatenation with prefix and suffix."""
214214
assert _concat_message(msg, prefix, suffix) == expected_result
215+
216+
217+
def test_logger_level(logging_machine, caplog):
218+
"""Test get/set Logger level."""
219+
220+
assert logging_machine.get_level() == stdlogging.WARN
221+
222+
logging_machine.info("info1")
223+
logging_machine.warning("warn1")
224+
225+
assert "info1" not in caplog.text
226+
assert "warn1" in caplog.text
227+
228+
logging_machine.setLevel(stdlogging.INFO)
229+
230+
assert logging_machine.get_level() == stdlogging.INFO
231+
232+
logging_machine.info("info2")
233+
logging_machine.warning("warn2")
234+
235+
assert "info2" in caplog.text
236+
assert "warn2" in caplog.text

0 commit comments

Comments
 (0)