Skip to content

Commit

Permalink
Add optional TID definition to the systemd sink send (gabime#2619)
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 authored and xinjian committed Mar 3, 2023
1 parent 4da3e27 commit ca58114
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/spdlog/sinks/systemd_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#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>

Expand Down Expand Up @@ -75,11 +76,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 ca58114

Please sign in to comment.