[systemd-devel] SyslogIdentifier does not work for messages printed with sd_journal_print
Martin Belanger
martin.belanger at cyaninc.com
Tue Jun 9 13:50:22 PDT 2015
Hi Lennart,
I found a workaround. When looking at the source code for sd_journal_print(),
I saw that SYSLOG_IDENTIFIER defaults to the string pointed to by
program_invocation_short_name
(defined in errno.h). So I simply create a new string with the text that I
want to assign to SYSLOG_IDENTIFIER and I make program_invocation_short_name
point to it.
It may not be the prettiest fix, but it works for the daemons I'm
instantiating.
Thanks,
Martin
Martin Belanger
Sr. Software Engineer[image: Cyan]1383 North McDowell Blvd.
Petaluma, CA 94954M(707)
481-3392Emartin.belanger at cyaninc.comwww.cyaninc.com[image:
Facebook] <http://www.facebook.com/CyanInc> [image: LinkedIn]
<http://www.linkedin.com/company/cyan-inc?trk=hb_tab_compy_id_2171992> [image:
Twitter] <http://twitter.com/CyanNews>
On Tue, Jun 9, 2015 at 3:16 AM, Lennart Poettering <lennart at poettering.net>
wrote:
> On Tue, 02.06.15 20:31, Martin Belanger (martin.belanger at cyaninc.com)
> wrote:
>
> > I'm using systemd 219 (Ubuntu 15.04).
> >
> > I have three instances of a daemon running. I use SyslogIdentifier to
> > give each of them a unique identifier (e.g. myproc-1, myproc-2,
> > myproc-3). I also redirect stdout/stderr to the journal using
> > StandardOutput=journal and StandardError=journal.
> >
> > I noticed that messages sent to the journal with printf (i.e. stdout)
> > get the proper SYSLOG_IDENTIFIER. However, messages send to the
> > journal with sd_journal_print() get the default SYSLOG_IDENTIFIER
> > (i.e. the process name). I also tried sd_journal_send() and get the
> > same result.
> >
> > Any thoughts as to why this is happening?
>
> SyslogIdentifier only really applies to stdout/stderr messages, not to
> native journal messages, which will not carry that id at all.
>
> The only reason the setting exists is because it's useful to set
> something there because stdout/stderr doesn't carry enough information
> for this, and because the same stdout/stderr stream can be shared
> among multiple processes it's difficult and misleading to
> automatically derive the identifier from them...
>
> Hence: I'd really prefer fi we didn't have that option at all, we
> justed added it, because it was difficult to do without...
>
> Lennart
>
> --
> Lennart Poettering, Red Hat
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20150609/b5beb2c6/attachment.html>
More information about the systemd-devel
mailing list