当前位置:编程学习 > python >>

Python logging 标准配置

原始出处:idea's blog
# encoding=UTF-8
import logging
import logging.config
 
logging.addLevelName(5, 'TRACE')
logging.addLevelName(30, 'WARN')
logging.addLevelName(50, 'FATAL')
 
logging.config.fileConfig('my.conf')
logger = logging.getLogger('root')
my.conf:
 www.zzzyk.com
[loggers]
keys=root
 
[handlers]
keys=consoleHandler, fileHandler
 
[formatters]
keys=易做图Formatter
 
[logger_root]
#level=ERROR
level=DEBUG
handlers=consoleHandler, fileHandler
 
[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=易做图Formatter
args=(sys.stdout,)
 
[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=易做图Formatter
args=('a.log', 'a')
 
[formatter_易做图Formatter]
#format=%(asctime)s [%(levelname)-5s] %(name)s %(message)s
format=%(asctime)s [%(levelname)-5s] %(message)s
#datefmt= %Y-%m-%d %H:%M:%S
datefmt=
补充:Web开发 , Python ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,