Browse Source

Merge branch 'release/1.11.2'

liuyuqi-dellpc 3 months ago
parent
commit
73fc89821b
3 changed files with 17 additions and 26 deletions
  1. 16 24
      repo_sync/utils/logger.py
  2. 1 1
      requirements-win.txt
  3. 0 1
      requirements.txt

+ 16 - 24
repo_sync/utils/logger.py

@@ -1,31 +1,23 @@
 import logging
 import logging
-from termcolor import colored
+from colorama import Fore, Style
+import colorama
+colorama.init()
 
 
 class ColoredFormatter(logging.Formatter):
 class ColoredFormatter(logging.Formatter):
+    COLOR_MAP = {
+        logging.DEBUG: Fore.BLUE,
+        logging.INFO: Fore.GREEN,
+        logging.WARNING: Fore.YELLOW,
+        logging.ERROR: Fore.RED,
+        logging.CRITICAL: Fore.MAGENTA
+    }
     def format(self, record):
     def format(self, record):
-        # 保留原始消息不变
-        import colorama
-        colorama.init()    # 解决windows cmd 颜色显示问题
-        original_msg = record.msg
-        if record.levelno == logging.DEBUG:
-            record.msg = colored(record.msg, 'blue')
-        elif record.levelno == logging.INFO:
-            record.msg = colored(record.msg, 'green')
-        elif record.levelno == logging.WARNING:
-            record.msg = colored(record.msg, 'yellow')
-        elif record.levelno == logging.ERROR:
-            record.msg = colored(record.msg, 'red')
-        elif record.levelno == logging.CRITICAL:
-            record.msg = colored(record.msg, 'magenta')
-        
-        # 调用父类格式化方法
-        formatted_message = super().format(record)
-        
-        # 恢复原始消息
-        record.msg = original_msg
-        
-        return formatted_message
-
+        msg = record.getMessage()
+        color = self.COLOR_MAP.get(record.levelno, '')
+        msg = color + msg + Style.RESET_ALL
+        record.message = msg
+        return super().format(record)
+    
 # Configure logger
 # Configure logger
 logger = logging.getLogger('repo_sync')
 logger = logging.getLogger('repo_sync')
 logger.setLevel(logging.INFO)
 logger.setLevel(logging.INFO)

+ 1 - 1
requirements-win.txt

@@ -2,4 +2,4 @@ requests==2.27.1
 python-dotenv==1.0.0
 python-dotenv==1.0.0
 PyQt5
 PyQt5
 pywin32
 pywin32
-termcolor==2.3.0
+colorama

+ 0 - 1
requirements.txt

@@ -1,4 +1,3 @@
 requests==2.27.1
 requests==2.27.1
 python-dotenv==1.0.0
 python-dotenv==1.0.0
-termcolor==2.3.0
 colorama
 colorama