From a44560ddb60a5bfc0a8927207c798209883f4dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Tue, 29 Oct 2019 20:39:26 +0100 Subject: [PATCH 1/2] journald: fix source file location This is what my manpage says, and what the original blog post [1] says as well. Also, `sd_journal_send` can add the location of its own invocation to the log. That's typically not what we want, so we have to suppress that feature and instead put whatever is inside the spdlog message into the journal. [1] http://0pointer.de/blog/projects/journal-submit.html --- include/spdlog/sinks/systemd_sink.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/spdlog/sinks/systemd_sink.h b/include/spdlog/sinks/systemd_sink.h index bad6442d..a9867a6f 100644 --- a/include/spdlog/sinks/systemd_sink.h +++ b/include/spdlog/sinks/systemd_sink.h @@ -8,6 +8,9 @@ #include "spdlog/details/synchronous_factory.h" #include +#ifndef SD_JOURNAL_SUPPRESS_LOCATION +#define SD_JOURNAL_SUPPRESS_LOCATION +#endif #include namespace spdlog { @@ -63,7 +66,7 @@ protected: else { err = (sd_journal_send)("MESSAGE=%.*s", static_cast(length), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level), - "SOURCE_FILE=%s", msg.source.filename, "SOURCE_LINE=%d", msg.source.line, "SOURCE_FUNC=%s", msg.source.funcname, nullptr); + "CODE_FILE=%s", msg.source.filename, "CODE_LINE=%d", msg.source.line, "CODE_FUNC=%s", msg.source.funcname, nullptr); } if (err) From 17513a6dce1b9c8f54885efa3d6764e5b46fe59d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Wed, 30 Oct 2019 10:51:07 +0100 Subject: [PATCH 2/2] journald: structured output for logger's name 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 --- include/spdlog/sinks/systemd_sink.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/spdlog/sinks/systemd_sink.h b/include/spdlog/sinks/systemd_sink.h index a9867a6f..2887e58e 100644 --- a/include/spdlog/sinks/systemd_sink.h +++ b/include/spdlog/sinks/systemd_sink.h @@ -61,11 +61,13 @@ protected: { // Note: function call inside '()' to avoid macro expansion err = (sd_journal_send)( - "MESSAGE=%.*s", static_cast(length), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level), nullptr); + "MESSAGE=%.*s", static_cast(length), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level), + "SYSLOG_IDENTIFIER=%.*s", static_cast(msg.logger_name.size()), msg.logger_name.data(), nullptr); } else { err = (sd_journal_send)("MESSAGE=%.*s", static_cast(length), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level), + "SYSLOG_IDENTIFIER=%.*s", static_cast(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); }