Skip to content

Commit

Permalink
Add optional TID definition to the systemd sink send
Browse files Browse the repository at this point in the history
From the systemd.journal-fields the TID is a user defined
field passed directly from the clients and stored in the
journal. Adding the arguement in the journal send to support
that storage option in the journal.
  • Loading branch information
chardin-cpi committed Jan 25, 2023
1 parent 5a58943 commit 0a41b05
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/spdlog/sinks/systemd_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
#include <spdlog/details/synchronous_factory.h>

#include <array>
#include <cstdint>
#ifndef SD_JOURNAL_SUPPRESS_LOCATION
# define SD_JOURNAL_SUPPRESS_LOCATION
#endif
#include <unistd.h>
#include <systemd/sd-journal.h>

namespace spdlog {
Expand Down Expand Up @@ -75,11 +77,17 @@ 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), payload.data(), "PRIORITY=%d", syslog_level(msg.level),
#ifndef SPDLOG_NO_THREAD_ID
"TID=%jd", static_cast<intmax_t>(gettid()),
#endif
"SYSLOG_IDENTIFIER=%.*s", static_cast<int>(syslog_identifier.size()), syslog_identifier.data(), nullptr);
}
else
{
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), payload.data(), "PRIORITY=%d", syslog_level(msg.level),
#ifndef SPDLOG_NO_THREAD_ID
"TID=%jd", static_cast<intmax_t>(gettid()),
#endif
"SYSLOG_IDENTIFIER=%.*s", static_cast<int>(syslog_identifier.size()), syslog_identifier.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 0a41b05

Please sign in to comment.