python的日志配置文件,支持写入到文件和控制台;支持滚动覆盖。
version: 1
disable_existing_loggers: False
formatters:
simple:
format: "%(asctime)s %(levelname)-8s [%(threadName)s] %(name)s %(filename)s: %(lineno)d: %(message)s"
handlers:
console:
class: logging.StreamHandler
level: INFO
formatter: simple
file:
class: logging.handlers.TimedRotatingFileHandler
filename: ./logs/application.log
level: INFO
formatter: simple
encoding: UTF-8
when: d
interval: 1
backupCount: 30
root:
level: INFO
handlers: [file,console]
logging_config_file = './conf/logging_config.yaml'
# 设置日志
with open(logging_config_file, 'r') as f:
config = yaml.safe_load(f.read())
logging.config.dictConfig(config)
logger = logging.getLogger(__name__)
使用起来相当爽!哈哈...
如果您觉得对您有所帮助,请点击关注一下呗!谢谢!