Add global level

This commit is contained in:
shenjack 2023-11-06 00:34:06 +08:00
parent 669377dcac
commit 7924397195
Signed by: shenjack
GPG Key ID: 7B1134A979775551
2 changed files with 26 additions and 1 deletions

View File

@ -8,7 +8,7 @@ from lib_not_dr.logger.logger import Logger
if __name__ == '__main__': if __name__ == '__main__':
logger = Logger.get_logger_by_name('test') logger = Logger.get_logger_by_name('test')
logger.level = 0 logger.global_level = 0
logger.info('Hello World!') logger.info('Hello World!')

View File

@ -63,6 +63,31 @@ class Logger(Options):
self.outputs.remove(output) self.outputs.remove(output)
self.level = max(self.level, *[output.level for output in self.outputs]) 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, def make_log(self,
messages: List[str], messages: List[str],
tag: Optional[str] = None, tag: Optional[str] = None,