我目前有控制台的日志设置。
import logging
import logging.config
logging.config.fileConfig('logging.conf')
logger = logging.getLogger('osPatch')
[loggers]
keys=root,osPatch
[handlers]
keys=consoleHandler
[formatters]
keys=osPatch
[logger_root]
level=DEBUG
handlers=consoleHandler
[logger_osPatch]
level=DEBUG
handlers=consoleHandler
qualname=osPatch
propagate=0
[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=osPatch
args=(sys.stdout,)
[formatter_osPatch]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=
这使控制台级别的日志记录非常好。
我想做的是编辑我的配置文件并使用
fileHandler
.
因此,我正在编辑我的配置文件:
[loggers]
keys=root,osPatch
[handlers]
keys=consoleHandler,FileHandler
[handler_FileHandler]
filename=example.log
level=DEBUG
formatter=osPatch
这给了我一个错误:
Traceback (most recent call last):
File "apply_errata.py", line 1, in <module>
import satellite_utils
File "/root/config-3.1.25/automated-os-patching/satellite_utils.py", line 3, in <module>
import system_utils
File "/root/config-3.1.25/automated-os-patching/system_utils.py", line 4, in <module>
import processing_utils
File "/root/config-3.1.25/automated-os-patching/processing_utils.py", line 7, in <module>
logging.config.fileConfig('logging.conf')
File "/usr/lib64/python3.4/logging/config.py", line 85, in fileConfig
_install_loggers(cp, handlers, disable_existing_loggers)
File "/usr/lib64/python3.4/logging/config.py", line 253, in _install_loggers
logger.addHandler(handlers[hand])
KeyError: 'FileHandler'
我做错了什么?