Skip to content

Commit

Permalink
journald: structured output for logger's name
Browse files Browse the repository at this point in the history
Previously, the logger name was effectively lost. There were two choices
on how to add it:

- Via a formatter, which would mean that `journalctl` would not be able
to filter against that. That would be suboptimal.

- As a "syslog identifier". This means that `journalctl` will, by
default, stop showing the daemon's executable name and replace that via
the logger name. The PID is still shown, and if one would like to go
back to the previous behavior, it is still possible via `journalctl -o
with-unit`.

I think that the second option is strictly better than the first one.

fixes #1289
  • Loading branch information
jktjkt committed Oct 30, 2019
1 parent e940b47 commit e4419c2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/spdlog/sinks/systemd_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ class systemd_sink : public base_sink<Mutex>
{
// Note: function call inside '()' to avoid macro expansion
err = (sd_journal_send)(
"MESSAGE=%.*s", static_cast<int>(length), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level), nullptr);
"MESSAGE=%.*s", static_cast<int>(length), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level),
"SYSLOG_IDENTIFIER=%.*s", static_cast<int>(msg.logger_name.size()), msg.logger_name.data(), nullptr);
}
else
{
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level),
"SYSLOG_IDENTIFIER=%.*s", static_cast<int>(msg.logger_name.size()), msg.logger_name.data(),
"CODE_FILE=%s", msg.source.filename, "CODE_LINE=%d", msg.source.line, "CODE_FUNC=%s", msg.source.funcname, nullptr);
}

Expand Down

0 comments on commit e4419c2

Please sign in to comment.