V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  ourpurple  ›  全部回复第 1 页 / 共 1 页
回复总数  1
2022-09-20 16:32:29 +08:00
回复了 ourpurple 创建的主题 Python 怎么用变量接收 INFO WARNING 信息
百度没找到。
在 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)
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2380 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 17ms · UTC 15:31 · PVG 23:31 · LAX 08:31 · JFK 11:31
Developed with CodeLauncher
♥ Do have faith in what you're doing.