Differences between revisions 3 and 4
Revision 3 as of 2005-09-07 02:52:19
Size: 847
Editor: c-67-162-247-97
Revision 4 as of 2008-07-08 11:27:43
Size: 847
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

logging module and %(filename)s

When using the logging module, the %(filename)s format option doesn't work. It always ends up in the output as "_ _init_ _.pyo".

The problem is that the module uses source file names to determine when it has walked back on the stack to the caller. In the py2exe environment, this (fragile) logic breaks. The following code will workaround the problem.


import sys
if hasattr(sys, "frozen"):
    import logging
    logging._srcfile = r"logging\__init__.pyo"

Note, this is in a Windows environment. The '\' should probably be replaced with a '/' for a Unix environment.

Update: this issue was opened as ticket 1276210 with the Python folks at SourceForge and they've checked in a fix as of 2005/09/02. No idea what release that will be available in.

LoggingModule (last edited 2008-07-08 11:27:43 by localhost)