Python Logging "KeyError" when loading fileConfig

I am trying to write a log in python; I would like to be able to load the configuration from a file, but I get an error after a call:

logging.config.fileConfig ('logging.conf') Traceback (last last call): File "/usr/lib64/python2.4/logging/config.py", line 157, in the Config log.addHandler file (handlers [hand] ) KeyError: 'simpleHandler'

My config:

[loggers] keys=root [handlers] keys=simpleHandler [formatters] keys=simpleFormatter [logger_root] level=DEBUG handlers=simpleHandler [handler_simpleHandler] formatter=simpleFormatter class=handlers.RotatingFileHandler filename=/tmp/test.log maxBytes=31457280 level=DEBUG [formatter_simpleFormatter] format=%(asctime)s %(levelname)s %(message)s datefmt=%Y/%m/%d %H:%M:%S 

Please help me determine what the error is, thanks.

+4
source share
2 answers

Try this in your manipulator file:

  [handler_simpleHandler] formatter=simpleFormatter class=handlers.RotatingFileHandler maxBytes=31457280 level=DEBUG args=('/tmp/test.log',) 
+3
source

Undoubtedly, the key 'simpleHandler' absent in any structure in which it must be found.

I suggest placing handler_foo sections handler_foo front of the handlers section - see if that helps. If this does not help, find another way to give your trusted handler a name.

-1
source

Source: https://habr.com/ru/post/1391660/


All Articles