| | |
| | | 异步日志管理器 |
| | | """ |
| | | import queue |
| | | import time |
| | | |
| | | from log_module.log import logger_debug |
| | | from utils import tool |
| | | |
| | | log_queue = queue.Queue() |
| | | |
| | | |
| | | def __add_log(logger, method, *args): |
| | | log_queue.put_nowait((logger, method, args)) |
| | | log_queue.put_nowait((logger, time.time(), method, args)) |
| | | |
| | | |
| | | def debug(logger, *args): |
| | |
| | | while True: |
| | | try: |
| | | val = log_queue.get() |
| | | cmd = val[1] |
| | | time_s = val[1] |
| | | cmd = val[2] |
| | | method = getattr(val[0], cmd) |
| | | method(*val[2]) |
| | | d = list(val[3]) |
| | | d[0] = f"[{tool.to_time_str(int(time_s))}.{str(time_s).split('.')[1][:3]}] " + d[0] |
| | | d = tuple(d) |
| | | method(*d) |
| | | except: |
| | | pass |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | logger_debug.warning() |
| | | info(logger_debug, "*-{}", "test") |
| | | # info(logger_debug, "*-{}", "test") |
| | | info(logger_debug, "123123") |
| | | run_sync() |