Peculiarity of '@' in logging.Formatter

2011-11-21 Thread Charlie Martin
This is what seems like an odd bug, but in code I'd thing often-enough used it 
must be the expected behavior and I just don't understand.  Please, 
sirs/mesdames, is this a bug?

Example code:
 begin code ---
#!/usr/bin/env python

"""
@-character WTF?
"""
import sys
import os
import logging, logging.handlers
import socket

log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)

fmtColon = logging.Formatter('[%(module)s:%(lineno)03d]:%(message)s')
strC = logging.handlers.SysLogHandler(address='/dev/log')
strC.setFormatter(fmtColon)
strC.setLevel(logging.DEBUG)
log.addHandler(strC)

fmtAt = logging.Formatter('[%(module)s@%(lineno)03d]:%(message)s')
strA = logging.handlers.SysLogHandler(address='/dev/log')
strA.setFormatter(fmtAt)
strA.setLevel(logging.DEBUG)
log.addHandler(strA)

log.info("My log message:isn't it special?")
 end code 

produces these entries in the syslog messages:

 begin results --
Nov 21 16:09:56 crmartin [atSign: 026]:My log message:isn't it special?
Nov 21 16:09:56 crmartin [atSign@026]: My log message:isn't it special?
 end results 

Observe: 

* in the first entry, "[atSign: 026]:My" with space after the first ":"; that 
space isn't in the format string.

* in the second entry "[atSign@026]: My" again has an additional space after 
the first ":"

the colons following are unchanged.

This **seems** like it must be some obscure bug, but perhaps it's some 
undocumented feature?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Peculiarity of '@' in logging.Formatter

2011-11-21 Thread Charlie Martin
Oops, forgot the python version etc:

bash $ /usr/bin/env python -V
Python 2.7

On SuSE 11.4

bash $ uname -a
Linux crmartin 2.6.37.6-0.9-desktop #1 SMP PREEMPT 2011-10-19 22:33:27 +0200 
x86_64 x86_64 x86_64 GNU/Linux
-- 
http://mail.python.org/mailman/listinfo/python-list