From 8888f5875e0dde5b7ff0967a339f787aacfb86cf Mon Sep 17 00:00:00 2001 From: Philippe Vaucher Date: Wed, 3 Jul 2024 21:51:11 +0200 Subject: [PATCH] Allow customization of syslog_sink (#3124) Thanks @Silex --- include/spdlog/sinks/syslog_sink.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/include/spdlog/sinks/syslog_sink.h b/include/spdlog/sinks/syslog_sink.h index ede10eb3a..913d41be6 100644 --- a/include/spdlog/sinks/syslog_sink.h +++ b/include/spdlog/sinks/syslog_sink.h @@ -3,14 +3,13 @@ #pragma once -#include +#include +#include +#include #include #include - -#include "../details/null_mutex.h" -#include "../details/synchronous_factory.h" -#include "./base_sink.h" +#include namespace spdlog { namespace sinks { @@ -18,7 +17,7 @@ namespace sinks { * Sink that write to syslog using the `syscall()` library call. */ template -class syslog_sink final : public base_sink { +class syslog_sink : public base_sink { public: syslog_sink(std::string ident, int syslog_option, int syslog_facility, bool enable_formatting) : enable_formatting_{enable_formatting}, @@ -65,13 +64,14 @@ class syslog_sink final : public base_sink { // // Simply maps spdlog's log level to syslog priority level. // - int syslog_prio_from_level(const details::log_msg &msg) const { - return syslog_levels_.at(static_cast(msg.log_level)); + virtual int syslog_prio_from_level(const details::log_msg &msg) const { + return syslog_levels_.at(static_cast(msg.level)); } -private: using levels_array = std::array; levels_array syslog_levels_; + +private: // must store the ident because the man says openlog might use the pointer as // is and not a string copy const std::string ident_; @@ -88,8 +88,8 @@ inline std::shared_ptr syslog_logger_mt(const std::string &logger_name, int syslog_option = 0, int syslog_facility = LOG_USER, bool enable_formatting = false) { - return Factory::template create(logger_name, syslog_ident, syslog_option, syslog_facility, - enable_formatting); + return Factory::template create(logger_name, syslog_ident, syslog_option, + syslog_facility, enable_formatting); } template @@ -98,7 +98,7 @@ inline std::shared_ptr syslog_logger_st(const std::string &logger_name, int syslog_option = 0, int syslog_facility = LOG_USER, bool enable_formatting = false) { - return Factory::template create(logger_name, syslog_ident, syslog_option, syslog_facility, - enable_formatting); + return Factory::template create(logger_name, syslog_ident, syslog_option, + syslog_facility, enable_formatting); } } // namespace spdlog