Search code examples
twistedsyslogrsyslog

How can you send structured-data to syslog from Twisted?


I am trying to send structured-data as defined in RFC5424 to syslog from Twisted. I'm on Ubuntu and the syslog implementation is rsyslog.

I'm running the twisted app with 'twistd --syslog', which sends messages sent with log.msg and log.err to syslog.

So far I have been trying to format the message in log.msg according to the spec, like this e.g.:

log.err('[exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"]')

But that does not work. Rsyslog just displays it as a regular message. Does anybody know how to do this? Should I look at a different logging library maybe?


Solution

  • It seems that the problem has nothing to do with Twisted's syslog integration but rather that Python's stdlib syslog module does not support the logging format described in RFC 5424.

    Furthermore RFC 5424 seems to be Dead On Arrival (at least the structured data part). It will most likely be replaced by the syntax described in Project lumberjack which is based on either JSON or XML. So if you are interested in more structured logging you should probably take a look at that.

    To format messages according to that standard one can use a custom formatter that conforms to the standard, like the one given here.