From e2c8c49f99ad1b3597fff8dcc67f4b799425d196 Mon Sep 17 00:00:00 2001 From: VisualDust Date: Tue, 8 Oct 2024 10:49:00 -0400 Subject: [PATCH] added global log level setter --- neetbox/logging/_logger.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/neetbox/logging/_logger.py b/neetbox/logging/_logger.py index d1d3fd5b..2c0a3c82 100644 --- a/neetbox/logging/_logger.py +++ b/neetbox/logging/_logger.py @@ -101,9 +101,25 @@ def log_level(self, level: Union[LogLevel, str]): "ERROR": LogLevel.ERROR, }[level] if type(level) is int: - assert level >= 0 and level <= 3 + assert level >= 0 and level <= 3, "log level must be in [0, 3]" level = LogLevel(level) self._log_level = level + + @classmethod + def set_global_log_level(cls, level: Union[LogLevel, str]): + if type(level) is str: + level = { + "ALL": LogLevel.ALL, + "DEBUG": LogLevel.DEBUG, + "INFO": LogLevel.INFO, + "WARNING": LogLevel.WARNING, + "ERROR": LogLevel.ERROR, + }[level] + if type(level) is int: + assert level >= 0 and level <= 3, "log level must be in [0, 3]" + level = LogLevel(level) + for logger in cls._IDENTITY2LOGGER.values(): + logger.log_level = level def writer(self, name: str): def _add_private_writer(name, writer_func: Callable):