Pulling log messages for a particular log in systemd journal

cjournalingsystemd

I was wondering if it is possible to pull log messages for a particular log with systemd's journal logging. For example, when I open a log in C, openlog('slog', LOG_CONS | LOG_PID, LOG_LOCAL1), to pull just messages logged under 'slog' or LOCAL1?

When I do something like journalctl -u slog or journalctl -u LOG_LOCAL1, it just tells me when the log begins and ends, not the actual log messages.

Best Answer

Yes, it is possible, but you passed the wrong switch to journalctl.

According to journalctl(1) man page:

  • To read messages with a given syslog identifier (say, "foo"), issue journalctl -t foo or journalctl SYSLOG_IDENTIFIER=foo;

  • To read messages with a given syslog facility, issue journalctl SYSLOG_FACILITY=1 (note that facilities are stored and matched using their numeric values).

More generally, the syslog identifier and facility are stored in the journal as separate fields (SYSLOG_IDENTIFIER and SYSLOG_FACILITY). If you ever need to access the journal from, say, the C API, you will have to add matches on these fields directly.

The journalctl -u switch is used to add a match on the name of a systemd unit which owned the process which has generated the message. So this is the wrong switch to use.