[TransWarp] peak.running.logs

Phillip J. Eby pje at telecommunity.com
Tue Aug 19 09:51:09 EDT 2003

At 01:34 PM 8/19/03 +0300, Yaroslav Samchuk wrote:

>the only way to avoid this exception is to call logger like:
>self.logger.info("%s", "log percent sign %")
>is it a bug or a feature?

A feature.  It's assumed that most logging messages will contain variables, 
so the logging calls take a format string followed by arguments.  These 
arguments are only interpolated if the log is not suppressing messages at 
its current detail level.  This improves performance for e.g. debug 
logging, because the string processing to insert the variables doesn't 
occur unless the message is actually being output.

To prevent interpolation, you can double up the % signs, e.g.:

self.logger.info("log percent sign %%")

Or, if the string is dynamic, then either:


or simply:

self.logger.info("%s", someVar)

The latter format is somewhat more efficient if there's a chance the log 
entry may be suppressed.

Note that the interface I used here is identical to that of the Python 2.3 
'logging' package's "logger" objects.

More information about the PEAK mailing list