| | |
| | | import queue |
| | | import time |
| | | |
| | | from log_module.log import logger_debug |
| | | from log_module.log import logger_debug, logger_system |
| | | from utils import tool |
| | | |
| | | |
| | |
| | | |
| | | # 运行同步日志 |
| | | def run_sync(self): |
| | | logger_system.info(f"run_sync 线程ID:{tool.get_thread_id()}") |
| | | while True: |
| | | try: |
| | | val = self.__log_queue.get() |
| | |
| | | |
| | | l2_data_log = AsyncLogManager() |
| | | |
| | | huaxin_l2_log = AsyncLogManager() |
| | | |
| | | log_queue = queue.Queue() |
| | | |
| | | |
| | | def __add_log(logger, method, *args): |
| | | log_queue.put_nowait((logger, time.time(), method, args)) |
| | | def __add_log(logger, time_out_log, method, *args): |
| | | start_time = time.time() |
| | | log_queue.put_nowait((logger, start_time, method, args)) |
| | | if time_out_log: |
| | | end_time = time.time() |
| | | sub_time = end_time - start_time |
| | | if sub_time > 0.01: |
| | | # 记录日志保存慢的日志 |
| | | __add_log(logger_debug, False, f"保存到日志队列用时:{sub_time}s") |
| | | |
| | | |
| | | def debug(logger, *args): |
| | | __add_log(logger, "debug", *args) |
| | | __add_log(logger, True, "debug", *args) |
| | | |
| | | |
| | | def info(logger, *args): |
| | | __add_log(logger, "info", *args) |
| | | __add_log(logger, True, "info", *args) |
| | | |
| | | |
| | | def warning(logger, *args): |
| | | __add_log(logger, "warning", *args) |
| | | __add_log(logger, True, "warning", *args) |
| | | |
| | | |
| | | def error(logger, *args): |
| | | __add_log(logger, "error", *args) |
| | | __add_log(logger, True, "error", *args) |
| | | |
| | | |
| | | def exception(logger, *args): |
| | | __add_log(logger, "exception", *args) |
| | | __add_log(logger, True, "exception", *args) |
| | | |
| | | |
| | | # 运行同步日志 |
| | | def run_sync(): |
| | | logger_system.info(f"async_log 线程ID:{tool.get_thread_id()}") |
| | | while True: |
| | | try: |
| | | val = log_queue.get() |
| | |
| | | |
| | | if __name__ == "__main__": |
| | | # info(logger_debug, "*-{}", "test") |
| | | info(logger_debug, "123123") |
| | | info(logger_debug, "002375") |
| | | run_sync() |