我有一个日志记录配置文件:
logger_config.yml
version: 1
formatters:
simple:
format: '%(asctime)s - %(levelname)s - %(message)s'
handlers:
console:
class: logging.StreamHandler
level: DEBUG
formatter: simple
stream: ext://sys.stdout
file:
class: logging.FileHandler
level: DEBUG
formatter: simple
filename: train.log
loggers:
trainLogger:
level: DEBUG
handlers: [console]
propagate: 1
root:
level: DEBUG
handlers: [console]
propagate: 1
还有一个简单的脚本:
测试.py
import logging
import logging.config
import yaml
with open('logging_config.yml', 'rt') as f:
config = yaml.safe_load(f.read())
logging.config.dictConfig(config)
# create logger
logger = logging.getLogger(__name__)
# 'application' code
logger.debug('debug message')
logger.info('info message')
logger.warn('warn message')
logger.error('error message')
logger.critical('critical message')
当我运行test.py
时,假设脚本将只登录控制台,因为handler
forroot
是console
,但也创建了一个空的 train.log。为什么这个附加?