Differences between revisions 1 and 2
Revision 1 as of 2005-08-30 01:07:40
Size: 663
Editor: c-67-162-247-97
Comment:
Revision 2 as of 2005-08-30 08:53:49
Size: 664
Editor: www
Comment: Make the string containing the backslash a raw string.
Deletions are marked like this. Additions are marked like this.
Line 12: Line 12:
    logging._srcfile = "logging\__init__.pyo"     logging._srcfile = r"logging\__init__.pyo"

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.

Example

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.

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