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 Feb 2, 2023
1 parent 5a58943 commit 246aa67
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 @@ -4,10 +4,12 @@
#pragma once

#include <spdlog/sinks/base_sink.h>
#include <spdlog/details/os.h>
#include <spdlog/details/null_mutex.h>
#include <spdlog/details/synchronous_factory.h>

#include <array>
#include <cstdint>
#ifndef SD_JOURNAL_SUPPRESS_LOCATION
# define SD_JOURNAL_SUPPRESS_LOCATION
#endif
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=%zu", os::thread_id(),
#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=%zu", os::thread_id(),
#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 246aa67

Please sign in to comment.