Administrator
2023-08-23 9d655c667cb40ba64e3f6fe5400c9e8c139e9988
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
异步日志管理器
"""
import queue
 
from log_module.log import logger_debug
 
log_queue = queue.Queue()
 
 
def __add_log(logger, method, *args):
    log_queue.put_nowait((logger, method, args))
 
 
def debug(logger, *args):
    __add_log(logger, "debug", *args)
 
 
def info(logger, *args):
    __add_log(logger, "info", *args)
 
 
def warning(logger, *args):
    __add_log(logger, "warning", *args)
 
 
def error(logger, *args):
    __add_log(logger, "error", *args)
 
 
def exception(logger, *args):
    __add_log(logger, "exception", *args)
 
 
# 运行同步日志
def run_sync():
    while True:
        try:
            val = log_queue.get()
            cmd = val[1]
            method = getattr(val[0], cmd)
            method(*val[2])
        except:
            pass
 
 
if __name__ == "__main__":
    logger_debug.warning()
    info(logger_debug, "*-{}", "test")
    run_sync()