Peculiarity of '@' in logging.Formatter

Vinay Sajip vinay_sajip at yahoo.co.uk
Wed Nov 23 07:54:16 EST 2011


On Nov 21, 11:17 pm, Charlie Martin <chasrmar... at gmail.com> wrote:
> 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?

It may be a bug, but if so, it's in the syslog daemon rather than
logging. Please try again with FileHandlers in place of
SysLogHandlers, and confirm whether the anomaly still occurs.

I could reproduce the problem on a Suse 11.3 machine running Python
2.6, but it doesn't occur on Ubuntu for example:

Nov 23 12:33:09 eta-jaunty [slhtest3:026]:My log message:isn't it
special?
Nov 23 12:33:09 eta-jaunty [slhtest3 at 026]:My log message:isn't it
special?

I get the same (expected) result on Ubuntu for both Python 2.6 and
2.7.

I noticed that on Suse the syslog daemon is rsyslogd, whereas on
Ubuntu it's plain syslogd. Daemons do differ on how they parse
messages :-(

I ran the script with strace, and logging is writing correctly to the
socket:

socket(PF_FILE, SOCK_DGRAM, 0)          = 3
connect(3, {sa_family=AF_FILE, path="/dev/log"}, 10) = 0
socket(PF_FILE, SOCK_DGRAM, 0)          = 4
connect(4, {sa_family=AF_FILE, path="/dev/log"}, 10) = 0
gettimeofday({1322052499, 78501}, NULL) = 0
send(3, "<14>[slhtest:026]:My log message"..., 51, 0) = 51
send(4, "<14>[slhtest at 026]:My log message"..., 51, 0) = 51
close(4)                                = 0
close(3)                                = 0

This is on Suse 11.3, where the formatting anomaly does occur - so it
appears to be down to how rsyslogd does things.

Regards,

Vinay Sajip



More information about the Python-list mailing list