On Mon, 7 Apr 2014, Oliver Bestwalter wrote:

Hi David,


On 7 April 2014 19:07, David Lang <[email protected]> wrote:

write a log with the format RSYSLOG_DebugFormat and you will see the
rawlog that rsyslog received and how it's been parsed.



Thanks, will do that and check what's going on.


the bottom line is that you are sending a log that's not in the correct
format, so the first word is being parsed into a different variable than
%msg% (probably systlogtag)


o.k. but as I did not change any defaults in the logging settings, this
would mean that logging to syslog from Python is broken by default ...

no, it just means you are misunderstanding things in Python.

when you log via logger, it adds a syslogtag, when you are logging with python, you are probably supposed to provide a syslog tag that you aren't giving it. (although, I'm surprised it doesn't default to argv[0], but I'm not a python expert)

David Lang

Cheers
Oliver



David Lang

On Mon, 7 Apr 2014, Oliver Bestwalter wrote:

 Date: Mon, 7 Apr 2014 14:36:00 +0200
From: Oliver Bestwalter <[email protected]>
Reply-To: rsyslog-users <[email protected]>
To: rsyslog-users <[email protected]>
Subject: [rsyslog] Logging from python: first wird of message not part of
    %msg% property?


Hi,

is there something special about the first word of the log message when I
use the sysloghandler in Python? I get different results depending on if I
sent the same message from the command line with logger or from Python.

Here is my script and config to reproduce this:

[PYTHON SCRIPT]
import logging
from logging.handlers import SysLogHandler
import subprocess
import time

msg = "firstwordofmessage rest of message %s" % (time.time())

log = logging.getLogger()
log.setLevel(logging.DEBUG)
log.addHandler(SysLogHandler("/dev/log", facility=SysLogHandler.LOG_
LOCAL0))
log.warning(msg + " from python logger")

cmd = "logger -p local0.warning %s from command line" % (msg)
subprocess.call(cmd.split(" "))

---

[RSYSLOG CONFIG]

$template debugFile,"/tmp/test/%msg%"
local0.* ?debugFile


[contents of /tmp/test after excution]

14:22:57 obestwalter@wroz [0] < /tmp/test >  596 %
ls
firstwordofmessage rest of message 1396873380.71 from command line
rest of message 1396873380.71 from python logger

The file names start with a space in both cases but from python the first
word went missing. I went through it with the debugger to see what happens
on the Python side: the message is prepended with <130> in (which is the
numerical prio/facility).

[content of the file from python log]

Apr  7 14:34:43 wroz firstwordofmessage rest of message 1396874083.19 from
python logger

Can someone help me to understand?

Cheers
Oliver
_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards
NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad
of sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you
DON'T LIKE THAT.

 _______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards
NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad
of sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you
DON'T LIKE THAT.

_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards
NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad of 
sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you DON'T LIKE 
THAT.

_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards
NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad of 
sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you DON'T LIKE 
THAT.

Reply via email to