From 300cd8f128dd74ae7c3602ae3895f4d34312193e Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期四, 21 三月 2024 18:17:06 +0800 Subject: [PATCH] L2数据插入主动卖单 --- log_module/async_log_util.py | 53 ++++++++++++++++++++++++++++++++++------------------- 1 files changed, 34 insertions(+), 19 deletions(-) diff --git a/log_module/async_log_util.py b/log_module/async_log_util.py index 811765e..6640308 100644 --- a/log_module/async_log_util.py +++ b/log_module/async_log_util.py @@ -1,7 +1,9 @@ """ 寮傛鏃ュ織绠$悊鍣� """ +import logging import queue +import threading import time from log_module.log import logger_debug, logger_system @@ -9,10 +11,15 @@ class AsyncLogManager: - __log_queue = queue.Queue() + + def __init__(self): + self.__log_queue = queue.Queue() def __add_log(self, logger, method, *args): self.__log_queue.put_nowait((logger, time.time(), method, args)) + + def add_log(self, data): + self.__log_queue.put_nowait(data) def debug(self, logger, *args): self.__add_log(logger, "debug", *args) @@ -30,56 +37,64 @@ self.__add_log(logger, "exception", *args) # 杩愯鍚屾鏃ュ織 - def run_sync(self): + def run_sync(self, add_to_common_log=False): + print("run_sync", add_to_common_log) logger_system.info(f"run_sync 绾跨▼ID:{tool.get_thread_id()}") while True: try: val = self.__log_queue.get() - time_s = val[1] - cmd = val[2] - method = getattr(val[0], cmd) - d = list(val[3]) - d[0] = f"[{tool.to_time_str(int(time_s))}.{str(time_s).split('.')[1][:6]}] " + d[0] - d = tuple(d) - method(*d) - except: - pass + if not add_to_common_log: + time_s = val[1] + cmd = val[2] + method = getattr(val[0], cmd) + d = list(val[3]) + d[0] = f"[{tool.to_time_str(int(time_s))}.{str(time_s).split('.')[1][:6]}] " + d[0] + d = tuple(d) + method(*d) + else: + _common_log.add_log(val) + except Exception as e: + logging.exception(e) l2_data_log = AsyncLogManager() huaxin_l2_log = AsyncLogManager() -__common_log = AsyncLogManager() +_common_log = AsyncLogManager() def debug(logger, *args): - __common_log.debug(logger, *args) + _common_log.debug(logger, *args) def info(logger, *args): - __common_log.info(logger, *args) + _common_log.info(logger, *args) def warning(logger, *args): - __common_log.warning(logger, *args) + _common_log.warning(logger, *args) def error(logger, *args): - __common_log.error(logger, *args) + _common_log.error(logger, *args) def exception(logger, *args): - __common_log.exception(logger, *args) + _common_log.exception(logger, *args) # 杩愯鍚屾鏃ュ織 def run_sync(): logger_system.info(f"async_log 绾跨▼ID:{tool.get_thread_id()}") - __common_log.run_sync() + _common_log.run_sync() if __name__ == "__main__": # info(logger_debug, "*-{}", "test") - info(logger_debug, "002375") + asyncLogManager = AsyncLogManager() + asyncLogManager.info(logger_debug, "娴嬭瘯123") + threading.Thread(target=lambda: asyncLogManager.run_sync(), daemon=True).start() + time.sleep(1) + # info(logger_debug, "002375") run_sync() -- Gitblit v1.8.0