11import ctypes
22import logging
3+ import logging .handlers
34import os
45import signal
56import sys
67import time
78from typing import Optional
89
9- import named_pipe
1010import psutil
1111import win32con
1212import win32gui
1313import wx
14+
15+ import named_pipe
1416from common import Window , XandY , load_json , local_path , match , single_call
1517from device import DeviceChangeCallback , DeviceChangeService
1618from gui import TaskbarIcon , WxApp , about_dialog , radio_menu
@@ -25,7 +27,7 @@ def filter(self, record):
2527 try :
2628 return not (
2729 # sometimes the record has msg, sometimes its message. Just try to catch all of them
28- 'Release ' in getattr (record , 'message' , getattr (record , 'msg' , '' )) and record .name == 'comtypes'
30+ 'Release ' in getattr (record , 'message' , getattr (record , 'msg' , '' )) and record .name . startswith ( 'comtypes' )
2931 )
3032 except Exception :
3133 # sometimes (rarely) record doesn't have a `message` attr
@@ -213,12 +215,16 @@ def shutdown(*_):
213215
214216if __name__ == '__main__' :
215217 ctypes .windll .shcore .SetProcessDpiAwareness (2 )
216- logging .basicConfig (
217- filename = local_path ('log.txt' ), filemode = 'w' ,
218- format = '[%(process)d] %(asctime)s:%(levelname)s:%(name)s:%(message)s'
218+ log_handler = logging .handlers .RotatingFileHandler (
219+ local_path ('log.txt' ), mode = 'a' , maxBytes = 1 * 1024 * 1024 , backupCount = 2 , encoding = 'utf-8' , delay = False
219220 )
220221 # filter the excessive comtypes logs
221- logging .getLogger ('comtypes' ).addFilter (LoggingFilter ())
222+ log_handler .addFilter (LoggingFilter ())
223+ logging .basicConfig (
224+ format = '[%(process)d] %(asctime)s:%(levelname)s:%(name)s:%(message)s' ,
225+ handlers = [log_handler ],
226+ level = logging .INFO
227+ )
222228 log = logging .getLogger (__name__ )
223229 log .info ('start' )
224230
0 commit comments