From 403f53e86f04ce0efb285d5d60c8519ab8ce1e15 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期五, 15 九月 2023 10:56:00 +0800
Subject: [PATCH] 注释下单阻止

---
 log_module/async_log_util.py |   61 +++++++++++++++++++++++++++---
 1 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/log_module/async_log_util.py b/log_module/async_log_util.py
index f72143a..a683474 100644
--- a/log_module/async_log_util.py
+++ b/log_module/async_log_util.py
@@ -2,14 +2,58 @@
 寮傛鏃ュ織绠$悊鍣�
 """
 import queue
+import time
 
-from log_module.log import logger_debug
+from log_module.log import logger_debug, logger_system
+from utils import tool
+
+
+class AsyncLogManager:
+    __log_queue = queue.Queue()
+
+    def __add_log(self, logger, method, *args):
+        self.__log_queue.put_nowait((logger, time.time(), method, args))
+
+    def debug(self, logger, *args):
+        self.__add_log(logger, "debug", *args)
+
+    def info(self, logger, *args):
+        self.__add_log(logger, "info", *args)
+
+    def warning(self, logger, *args):
+        self.__add_log(logger, "warning", *args)
+
+    def error(self, logger, *args):
+        self.__add_log(logger, "error", *args)
+
+    def exception(self, logger, *args):
+        self.__add_log(logger, "exception", *args)
+
+    # 杩愯鍚屾鏃ュ織
+    def run_sync(self):
+        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][:3]}] " + d[0]
+                d = tuple(d)
+                method(*d)
+            except:
+                pass
+
+
+l2_data_log = AsyncLogManager()
+
 
 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):
@@ -34,17 +78,22 @@
 
 # 杩愯鍚屾鏃ュ織
 def run_sync():
+    logger_system.info(f"async_log 绾跨▼ID:{tool.get_thread_id()}")
     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()

--
Gitblit v1.8.0