[systemd-devel] [RFC PATCH] systemd-python: add SYSLOG_IDENTIFIER to JournalHandler
Zbigniew Jędrzejewski-Szmek
zbyszek at in.waw.pl
Tue Apr 23 16:53:15 PDT 2013
On Tue, Apr 23, 2013 at 06:54:55PM +0300, Marti Raudsepp wrote:
> On Mon, Apr 22, 2013 at 11:31 PM, Zbigniew Jędrzejewski-Szmek
> <zbyszek at in.waw.pl> wrote:
> > Otherwise, we get SYSLOG_IDENTIFIER=python or something
> > similar, which is completely useless.
>
> I think we shouldn't be creating one-off arguments for every possible
> field someone might want to add, but something more generic -- take a
> dict as argument for example.
That'd be relatively easy to do. But there's the question what
fields can be meaningfully attached at (a) the handler level and at
(b) logger level and what at (c) individual event level.
It'd be strange to all messages from a program to include a fixed set
of repeating fields in (a). We already have PRIORITY set from the log
level, SYSLOG_IDENTIFIER should of course be added, but that's about
it. We can allow additional fields with a few lines of code.
(b) is technically hard, IIUC, because of python logging API
limiations.
(c) should be possible.
> Ideally it would be possible to attach custom journal fields to the
> Python root logger and have them propagate to all loggers from there.
> But I tried and couldn't make it work without the code getting really
> ugly. Here are some of my thoughts on the topic:
> http://lists.freedesktop.org/archives/systemd-devel/2012-October/006937.html
> And a reply: http://lists.freedesktop.org/archives/systemd-devel/2012-November/007372.html
>
> Note that Python's SysLogHandler has something vaguely similar, but
> it's pretty annoying to use. It's not a constructor argument, but an
> attribute you have to override and is simply prepended to the syslog
> message so you also have to include the separating colon and space
> (like in the C syslog API).
>
> import logging, logging.handlers
> h=logging.handlers.SysLogHandler(address='/dev/log')
> h.ident='somename: '
>
> l= logging.getLogger('froggerlogger')
> l.propagate = False
> l.addHandler(h)
> l.warning('foo')
This is analogous to case (a), we can do that better.
Zbyszek
More information about the systemd-devel
mailing list