Skip to content

Commit

Permalink
Allow customization of syslog_sink (#3124)
Browse files Browse the repository at this point in the history
Thanks @Silex
  • Loading branch information
Silex authored and gabime committed Nov 25, 2024
1 parent dec6a3f commit 8888f58
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions include/spdlog/sinks/syslog_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@

#pragma once

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

#include <array>
#include <string>

#include "../details/null_mutex.h"
#include "../details/synchronous_factory.h"
#include "./base_sink.h"
#include <syslog.h>

namespace spdlog {
namespace sinks {
/**
* Sink that write to syslog using the `syscall()` library call.
*/
template <typename Mutex>
class syslog_sink final : public base_sink<Mutex> {
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},
Expand Down Expand Up @@ -65,13 +64,14 @@ class syslog_sink final : public base_sink<Mutex> {
//
// 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<levels_array::size_type>(msg.log_level));
virtual int syslog_prio_from_level(const details::log_msg &msg) const {
return syslog_levels_.at(static_cast<levels_array::size_type>(msg.level));
}

private:
using levels_array = std::array<int, 7>;
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_;
Expand All @@ -88,8 +88,8 @@ inline std::shared_ptr<logger> 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<sinks::syslog_sink_mt>(logger_name, syslog_ident, syslog_option, syslog_facility,
enable_formatting);
return Factory::template create<sinks::syslog_sink_mt>(logger_name, syslog_ident, syslog_option,
syslog_facility, enable_formatting);
}

template <typename Factory = spdlog::synchronous_factory>
Expand All @@ -98,7 +98,7 @@ inline std::shared_ptr<logger> 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<sinks::syslog_sink_st>(logger_name, syslog_ident, syslog_option, syslog_facility,
enable_formatting);
return Factory::template create<sinks::syslog_sink_st>(logger_name, syslog_ident, syslog_option,
syslog_facility, enable_formatting);
}
} // namespace spdlog

0 comments on commit 8888f58

Please sign in to comment.