AttributeError: logging module bug ?

Peter vmail at mycircuit.org
Fri Dec 18 22:18:26 EST 2009


> ./of/logger.py
>
> from logging import Formatter
>
> class RootFormatter(Formatter):
>      pass
> class ModuleFormatter(Formatter):
>      pass
> class ClassFormatter(Formatter):
>      pass
> class DataFormatter(Formatter):
>      pass
>
> (and an empty ./of/__init__.py) your initial script runs without error. If
> you want external help please
>
> (1) make sure that you provide all necessary files needed to reproduce the
> error
>
> (2) remove as much of the code as possible that does not contribute to the
> problem. (This is also an effective debugging technique)
>
> Peter
>    
(1), (2): That is sometimes easier said than done, especially if you 
still lack experience in a given language. You are right, though, my 
request lacked precision, sorry for the noise !
Your answer helped me to find the problem:

given the minimal files above, in my logging.cfg file , I specified:

[formatter_root]
format=%(levelname)s %(name)s %(message)s
datefmt=%S
# does not work:
class = of.logger.RootFormatter

based on my misunderstanding, that the path to the RootFormatter could 
be specfied as a normal python class defined in a package.module .

It seems that I have to say instead:
....
# works:
class = logger.RootFormatter

This was somehow unexpected for me, since in a module using logger.py, I 
could use either import:

from mylogger import logger  # without package name

or

from of.mylogger import logger  # with package name

but this does not seem to work for the class specification in the config 
file (only the former works).

Again, thanks a lot !
Peter






More information about the Python-list mailing list