From 792439719591d7adf9c9150145256a9203bb095a Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Mon, 6 Nov 2023 00:34:06 +0800 Subject: [PATCH] Add global level --- example/logger/logger.py | 2 +- lib_not_dr/logger/logger.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/example/logger/logger.py b/example/logger/logger.py index e45136f..23cbed4 100644 --- a/example/logger/logger.py +++ b/example/logger/logger.py @@ -8,7 +8,7 @@ from lib_not_dr.logger.logger import Logger if __name__ == '__main__': logger = Logger.get_logger_by_name('test') - logger.level = 0 + logger.global_level = 0 logger.info('Hello World!') diff --git a/lib_not_dr/logger/logger.py b/lib_not_dr/logger/logger.py index 7bfad16..020edbc 100644 --- a/lib_not_dr/logger/logger.py +++ b/lib_not_dr/logger/logger.py @@ -63,6 +63,31 @@ class Logger(Options): self.outputs.remove(output) self.level = max(self.level, *[output.level for output in self.outputs]) + @property + def global_level(self) -> int: + """ + Get the global logging level. + + Returns: + int: The global logging level. + """ + return self.level + + @global_level.setter + def global_level(self, level: int) -> None: + """ + Set the global logging level. + + Args: + level (int): The global logging level. + + Returns: + None + """ + self.level = level + for output in self.outputs: + output.level = level + def make_log(self, messages: List[str], tag: Optional[str] = None,