Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Logging "KeyError" when loading fileConfig

Tags:

python

logging

I'm trying to write out to a log in python; I would like to be able to load the configuration from a file, but I am getting an error after calling:

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

My config is:

  [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.

like image 493
Blaskovicz Avatar asked Nov 05 '22 07:11

Blaskovicz


1 Answers

Try this in your filehandler:

    [handler_simpleHandler]
    formatter=simpleFormatter
    class=handlers.RotatingFileHandler
    maxBytes=31457280
    level=DEBUG
    args=('/tmp/test.log',)
like image 185
Bogdan Avatar answered Nov 09 '22 14:11

Bogdan