clang-format
This commit is contained in:
parent
517ccc4088
commit
f5831d5132
@ -72,4 +72,3 @@ std::shared_ptr<logger> stderr_logger_st(const std::string &logger_name);
|
||||
} // namespace spdlog
|
||||
|
||||
#include "stdout_sinks-inl.h"
|
||||
|
||||
|
@ -22,15 +22,13 @@ class syslog_sink : public base_sink<Mutex>
|
||||
public:
|
||||
syslog_sink(std::string ident, int syslog_option, int syslog_facility, bool enable_formatting)
|
||||
: enable_formatting_{enable_formatting}
|
||||
, syslog_levels_{
|
||||
/* spdlog::level::trace */ LOG_DEBUG,
|
||||
/* spdlog::level::debug */ LOG_DEBUG,
|
||||
/* spdlog::level::info */ LOG_INFO,
|
||||
/* spdlog::level::warn */ LOG_WARNING,
|
||||
/* spdlog::level::err */ LOG_ERR,
|
||||
/* spdlog::level::critical */ LOG_CRIT,
|
||||
/* spdlog::level::off */ LOG_INFO
|
||||
}
|
||||
, syslog_levels_{/* spdlog::level::trace */ LOG_DEBUG,
|
||||
/* spdlog::level::debug */ LOG_DEBUG,
|
||||
/* spdlog::level::info */ LOG_INFO,
|
||||
/* spdlog::level::warn */ LOG_WARNING,
|
||||
/* spdlog::level::err */ LOG_ERR,
|
||||
/* spdlog::level::critical */ LOG_CRIT,
|
||||
/* spdlog::level::off */ LOG_INFO}
|
||||
, ident_{std::move(ident)}
|
||||
{
|
||||
// set ident to be program name if empty
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
|
||||
|
||||
/**
|
||||
* Sink that write to systemd journal using the `sd_journal_send()` library call.
|
||||
*
|
||||
@ -23,15 +22,14 @@ class systemd_sink : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
//
|
||||
systemd_sink(): syslog_levels_{
|
||||
/* spdlog::level::trace */ LOG_DEBUG,
|
||||
/* spdlog::level::debug */ LOG_DEBUG,
|
||||
/* spdlog::level::info */ LOG_INFO,
|
||||
/* spdlog::level::warn */ LOG_WARNING,
|
||||
/* spdlog::level::err */ LOG_ERR,
|
||||
/* spdlog::level::critical */ LOG_CRIT,
|
||||
/* spdlog::level::off */ LOG_INFO
|
||||
}
|
||||
systemd_sink()
|
||||
: syslog_levels_{/* spdlog::level::trace */ LOG_DEBUG,
|
||||
/* spdlog::level::debug */ LOG_DEBUG,
|
||||
/* spdlog::level::info */ LOG_INFO,
|
||||
/* spdlog::level::warn */ LOG_WARNING,
|
||||
/* spdlog::level::err */ LOG_ERR,
|
||||
/* spdlog::level::critical */ LOG_CRIT,
|
||||
/* spdlog::level::off */ LOG_INFO}
|
||||
{}
|
||||
|
||||
~systemd_sink() override {}
|
||||
@ -40,7 +38,6 @@ public:
|
||||
systemd_sink &operator=(const systemd_sink &) = delete;
|
||||
|
||||
protected:
|
||||
|
||||
std::array<int, 7> syslog_levels_;
|
||||
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
@ -48,33 +45,25 @@ protected:
|
||||
int err;
|
||||
|
||||
// Do not send source location if not available
|
||||
if(msg.source.empty())
|
||||
if (msg.source.empty())
|
||||
{
|
||||
// Note: function call inside '()' to avoid macro expansion
|
||||
err = (sd_journal_send)(
|
||||
"MESSAGE=%.*s", static_cast<int>(msg.payload.size()), msg.payload.data(),
|
||||
"PRIORITY=%d", syslog_level(msg.level),
|
||||
nullptr);
|
||||
"MESSAGE=%.*s", static_cast<int>(msg.payload.size()), msg.payload.data(), "PRIORITY=%d", syslog_level(msg.level), nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
err = (sd_journal_send)(
|
||||
"MESSAGE=%.*s", static_cast<int>(msg.payload.size()), 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);
|
||||
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(msg.payload.size()), 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);
|
||||
}
|
||||
|
||||
if(err)
|
||||
if (err)
|
||||
{
|
||||
throw spdlog_ex("Failed writing to systemd", errno);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int syslog_level(level::level_enum l)
|
||||
{
|
||||
return syslog_levels_.at(static_cast<int>(l));
|
||||
|
@ -80,7 +80,6 @@ template std::shared_ptr<spdlog::logger> spdlog::stdout_color_st<spdlog::async_f
|
||||
template std::shared_ptr<spdlog::logger> spdlog::stderr_color_mt<spdlog::async_factory>(const std::string &logger_name, color_mode mode);
|
||||
template std::shared_ptr<spdlog::logger> spdlog::stderr_color_st<spdlog::async_factory>(const std::string &logger_name, color_mode mode);
|
||||
|
||||
|
||||
// Slightly modified version of fmt lib's format.cc source file.
|
||||
// Copyright (c) 2012 - 2016, Victor Zverovich
|
||||
// All rights reserved.
|
||||
|
@ -181,19 +181,16 @@ TEST_CASE("center_padded_short", "[pattern_formatter]")
|
||||
|
||||
TEST_CASE("left_padded_huge", "[pattern_formatter]")
|
||||
{
|
||||
REQUIRE(
|
||||
log_to_str("Some message", "[%-300n] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
REQUIRE(log_to_str("Some message", "[%-300n] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[pattern_tester ] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("left_padded_max", "[pattern_formatter]")
|
||||
{
|
||||
REQUIRE(
|
||||
log_to_str("Some message", "[%-64n] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
REQUIRE(log_to_str("Some message", "[%-64n] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[pattern_tester ] Some message\n");
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("clone-default-formatter", "[pattern_formatter]")
|
||||
{
|
||||
auto formatter_1 = std::make_shared<spdlog::pattern_formatter>();
|
||||
|
Loading…
Reference in New Issue
Block a user