Keyerror addhandler

S

Steven Macintyre

Hi all,

I'm wondering if anyone can assist me with this as I am very confused about
it now.

I am getting the following error;

Traceback (most recent call last):
File "/usr/lib/python2.4/logging/config.py", line 191, in fileConfig
logger.addHandler(handlers[hand])
KeyError: 'handler_mylogfileHandler'

My code:

import logging
import logging.config
import logging.handlers

#parse config file
logging.config.fileConfig("logging.conf")

#create logger
logger = logging.getLogger("pythonacro")

my config:

[loggers]
keys=root,pythonacro

[handlers]
keys=consoleHandler,mylogfileHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=DEBUG
handlers=consoleHandler

[logger_pythonacro]
level=DEBUG
handlers=consoleHandler,mylogfileHandler
propagate=1
qualname=pythonacro

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

[handler_mylogfileHandler]
class=RotatingFileHandler
level=DEBUG
formatter=simpleFormatter
args=('python_acro.log', 'a', 125829120, 5)
filename=python_acro.log
mode=a

[formatter_simpleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=

As far as I can tell, this is correct according to logging-config-fileformat
and documentation found on google.

Any ideas?

Many thanks

Steven
 
D

Diez B. Roggisch

Steven said:
Hi all,

I'm wondering if anyone can assist me with this as I am very confused about
it now.

I am getting the following error;

Traceback (most recent call last):
File "/usr/lib/python2.4/logging/config.py", line 191, in fileConfig
logger.addHandler(handlers[hand])
KeyError: 'handler_mylogfileHandler'

For me, that fails with

mac-dir:tmp deets$ python2.5 test.py
Traceback (most recent call last):
File "test.py", line 6, in <module>
logging.config.fileConfig("logging.conf")
File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/logging/config.py",
line 84, in fileConfig
handlers = _install_handlers(cp, formatters)
File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/logging/config.py",
line 149, in _install_handlers
klass = eval(klass, vars(logging))
File "<string>", line 1, in <module>
NameError: name 'RotatingFileHandler' is not defined
mac-dir:tmp deets$

Diez
 
S

Steven Macintyre

Hi Diez,

I am using 2.4, could that be the cuase of your issue below.

Ideally, I would like to stay with the 2.4 version and based on two
tutorials, this was what I came up with

Steven

Steven said:
Hi all,

I'm wondering if anyone can assist me with this as I am very confused about
it now.

I am getting the following error;

Traceback (most recent call last):
File "/usr/lib/python2.4/logging/config.py", line 191, in fileConfig
logger.addHandler(handlers[hand])
KeyError: 'handler_mylogfileHandler'

For me, that fails with

mac-dir:tmp deets$ python2.5 test.py
Traceback (most recent call last):
File "test.py", line 6, in <module>
logging.config.fileConfig("logging.conf")
File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/logging/con
fig.py",
line 84, in fileConfig
handlers = _install_handlers(cp, formatters)
File
"/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/logging/con
fig.py",
line 149, in _install_handlers
klass = eval(klass, vars(logging))
File "<string>", line 1, in <module>
NameError: name 'RotatingFileHandler' is not defined
mac-dir:tmp deets$

Diez
 
P

Peter Otten

Steven Macintyre wrote:

Please don't top-post.

[Diez B. Roggisch]
For me, that fails with
NameError: name 'RotatingFileHandler' is not defined

[Steven Macintyre]
I am using 2.4, could that be the cuase of your issue below.

Ideally, I would like to stay with the 2.4 version and based on two
tutorials, this was what I came up with

It looks like 2.5 has the better error message, but the actual problem is
the same for both versions. Try changing mylogfileHandler's class to

[handler_mylogfileHandler]
class=handlers.RotatingFileHandler

Peter
 
S

Steven Macintyre

Hi Peter,
It looks like 2.5 has the better error message, but the actual problem is
the same for both versions. Try changing mylogfileHandler's class to

[handler_mylogfileHandler]
class=handlers.RotatingFileHandler

Many thanks, this worked for me!

Steven
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top