[issue1436] logging.config.fileConfig, NameError: name 'RotatingFileHandler' is not defined

Vinay Sajip report at bugs.python.org
Tue Nov 13 19:46:35 CET 2007


Vinay Sajip added the comment:

This is not a bug: I think you are missing something. In the first
example (interactive usage), the lines "import logging" and "import
logging.handlers" do not magically introduce RotatingFileHandler into
your interactive session's globals. To do this, you would have to say
"from logging.handlers import RotatingFileHandler". An analogous example
unrelated to logging:

ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on
Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import httplib
>>> HTTP
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'HTTP' is not defined
>>> httplib.HTTP
<class httplib.HTTP at 0x00A759F0>
>>>

In the second example (using fileConfig), the documentation in

http://docs.python.org/lib/logging-config-fileformat.html

clearly states that the class and arguments are evaluated using the
logging package's namespace. This means that for a handler defined in
the logging package itself (such as StreamHandler) no qualification is
required, but for a handler defined in the handlers subpackage, you
should specify "handlers.RotatingFileHandler" in the configuration file
rather than "RotatingFileHandler" or "logging.handlers.RotatingFileHandler".

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1436>
__________________________________


More information about the Python-bugs-list mailing list