1
kkeep 2022-09-18 02:32:07 +08:00 via Android
接管 sydin🌝🌝
|
2
julyclyde 2022-09-19 10:09:38 +08:00
logging 库
改一下 handler 试试 |
3
ourpurple OP 百度没找到。
在 github 上找到了。 class Handler(logging.StreamHandler): def __init__(self): logging.StreamHandler.__init__(self) def emit(self, record): global buffer # record = f'{record.name}, [{record.levelname}], {record.message}' record = f'[{record.levelname}], {record.message}' buffer = f'{buffer}\n{record}'.strip() window['log'].update(value=buffer) log_file = 'run_log.txt' logging.basicConfig( level=logging.DEBUG, format='%(name)s, %(asctime)s, [%(levelname)s], %(message)s', filename=log_file, filemode='w') buffer = '' ch = Handler() ch.setLevel(logging.INFO) logging.getLogger('').addHandler(ch) |