reliable unit test logging

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sun Oct 7 00:29:13 EDT 2007


En Wed, 03 Oct 2007 11:37:57 -0300, Vyacheslav Maslov <vmaslov at swsoft.com>  
escribi�:

> I have one more question related to logging module, not unit test. I use
> FileHandler to append information to file log, in fact location of log
> file depends on some external factor and is calculated during
> initialization. Furthermore i want to use configuration file because it
> is comfortable way. So i need way to define in configuration file some
> variable which should evaluated during logging system initialization, i
> try following way:
>
> [handler_hand02]
> class=FileHandler
> level=NOTSET
> formatter=form01
> args=(logFileDir+"myfile.log","a",)
> logFileDir is defined in scope of module which call
> logging.config.fileConfig()
>
> and it produces "name 'logFileDir' is not defined" exception. As i
> understand this happens because inside logging module variable
> logFileDir is not visible. How i can avoid this?

logging.config uses the ConfigParser class; ConfigParser has some  
interpolation mechanism.
I think this should work (but I've not tested it):

[handler_hand02]
class=FileHandler
level=NOTSET
formatter=form01
args=("%(logFileDir)s"+"myfile.log","a",)

and call it using logging.config.fileConfig({"logFileDir":  
"your/desired/path"})

-- 
Gabriel Genellina




More information about the Python-list mailing list