百度没找到。
在 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)