KeyError: 'handlers.RotatingFileHandler'

Daiyue Weng daiyueweng at gmail.com
Mon Sep 12 12:27:11 EDT 2016


Hi, I am trying to use 'RotatingFileHandler' in a logging config file,

import logging
import logging.config
import logging.handlers

logging.config.fileConfig('logging.conf')


[loggers]
keys=root,ingestion_log

[handlers]
keys=consoleHandler,fileHandler

[formatters]
keys=ingestFormatter

[logger_root]
level=DEBUG
handlers=consoleHandler

[logger_ingestion_log]
level=DEBUG
handlers=handlers.RotatingFileHandler
maxBytes=51200
qualname=ingestion_log
propagate=0

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=Formatter
args=(sys.stdout,)

[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=Formatter
args=("log/logging.log",)

[formatter_Formatter]
format=pathname~%(pathname)s||timestamp~%(asctime)s||level~%(levelname)s||name~%(name)s||function_name~%(funcName)s||debug_message~%(message)s
datefmt=%m/%d/%Y %H:%M:%S


but Python generated a key error,

C:\Continuum\Anaconda3\lib\logging\config.py:85: in fileConfig
    _install_loggers(cp, handlers, disable_existing_loggers)
C:\Continuum\Anaconda3\lib\logging\config.py:254: in _install_loggers
    logger.addHandler(handlers[hand])
E   KeyError: 'handlers.RotatingFileHandler'

how to fix the errors?

thanks



More information about the Python-list mailing list