From b9461b39cdbc02499d1bc30201c82d4a8e1196b3 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Mon, 27 Jun 2022 14:42:26 +0800 Subject: [PATCH] =?UTF-8?q?logger=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/msdnicrosoft_logger/__init__.py | 9 +++++ libs/msdnicrosoft_logger/shenjack.py | 56 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 libs/msdnicrosoft_logger/shenjack.py diff --git a/libs/msdnicrosoft_logger/__init__.py b/libs/msdnicrosoft_logger/__init__.py index 23ed92e..e66fad3 100644 --- a/libs/msdnicrosoft_logger/__init__.py +++ b/libs/msdnicrosoft_logger/__init__.py @@ -156,9 +156,18 @@ class File: import atexit +from typing import Optional + color_reset_suffix = "\033[0m" +class LogFileCache: + """日志文件缓存""" + def __init__(self, time_cache: Optional[int, float] = 1, log_cache: int = 10): + self.time_cache = time_cache + self.log_cache = log_cache + + class Logger: """shenjack logger""" diff --git a/libs/msdnicrosoft_logger/shenjack.py b/libs/msdnicrosoft_logger/shenjack.py new file mode 100644 index 0000000..af49b0d --- /dev/null +++ b/libs/msdnicrosoft_logger/shenjack.py @@ -0,0 +1,56 @@ +import atexit +from time import strftime +from typing import Optional + +color_reset_suffix = "\033[0m" + + +class LogFileCache: + """日志文件缓存""" + + def __init__(self, file_name: str = 'logs//log.log', flush_time: Optional[int, float] = 1, cache_entries_num: int = 10): + # 配置相关 + self.log_file_name = file_name # log 文件名称 + self.flush_time = flush_time # 缓存刷新时长 + self.cache_entries_num = cache_entries_num + # 写入缓存数 + self.cache_count = 0 + + self.log_caches = [] + + + def _log_file_time_write(self) -> None: + """使用 threading.Timer 调用的定时写入日志文件的函数""" + if self.cache_count == 0: + return None + ... + + def make_log(self, string: str, wait4cache=True) -> None: + if wait4cache: + self.have_log_cache = True + else: + ... + + +class Logger: + """shenjack logger""" + + def __init__(self, config: dict = None) -> None: + if config is None: + self.config = {} + else: + self.config = config + + +class GetLogger: + """shenjack牌logger""" + + def __init__(self): + self.configs = {} + + def add_config(self, name: str, config: dict) -> dict: + self.configs[name] = config + return self.configs + + def logger(self, name: str = 'root') -> Logger: + return Logger(config=self.configs)