mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-28 08:20:19 +08:00
parent
dec6a3f61f
commit
8888f5875e
@ -3,14 +3,13 @@
|
|||||||
|
|
||||||
#pragma once
|
#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 <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <syslog.h>
|
||||||
#include "../details/null_mutex.h"
|
|
||||||
#include "../details/synchronous_factory.h"
|
|
||||||
#include "./base_sink.h"
|
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace sinks {
|
namespace sinks {
|
||||||
@ -18,7 +17,7 @@ namespace sinks {
|
|||||||
* Sink that write to syslog using the `syscall()` library call.
|
* Sink that write to syslog using the `syscall()` library call.
|
||||||
*/
|
*/
|
||||||
template <typename Mutex>
|
template <typename Mutex>
|
||||||
class syslog_sink final : public base_sink<Mutex> {
|
class syslog_sink : public base_sink<Mutex> {
|
||||||
public:
|
public:
|
||||||
syslog_sink(std::string ident, int syslog_option, int syslog_facility, bool enable_formatting)
|
syslog_sink(std::string ident, int syslog_option, int syslog_facility, bool enable_formatting)
|
||||||
: enable_formatting_{enable_formatting},
|
: enable_formatting_{enable_formatting},
|
||||||
@ -65,13 +64,14 @@ protected:
|
|||||||
//
|
//
|
||||||
// Simply maps spdlog's log level to syslog priority level.
|
// Simply maps spdlog's log level to syslog priority level.
|
||||||
//
|
//
|
||||||
int syslog_prio_from_level(const details::log_msg &msg) const {
|
virtual int syslog_prio_from_level(const details::log_msg &msg) const {
|
||||||
return syslog_levels_.at(static_cast<levels_array::size_type>(msg.log_level));
|
return syslog_levels_.at(static_cast<levels_array::size_type>(msg.level));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
using levels_array = std::array<int, 7>;
|
using levels_array = std::array<int, 7>;
|
||||||
levels_array syslog_levels_;
|
levels_array syslog_levels_;
|
||||||
|
|
||||||
|
private:
|
||||||
// must store the ident because the man says openlog might use the pointer as
|
// must store the ident because the man says openlog might use the pointer as
|
||||||
// is and not a string copy
|
// is and not a string copy
|
||||||
const std::string ident_;
|
const std::string ident_;
|
||||||
@ -88,8 +88,8 @@ inline std::shared_ptr<logger> syslog_logger_mt(const std::string &logger_name,
|
|||||||
int syslog_option = 0,
|
int syslog_option = 0,
|
||||||
int syslog_facility = LOG_USER,
|
int syslog_facility = LOG_USER,
|
||||||
bool enable_formatting = false) {
|
bool enable_formatting = false) {
|
||||||
return Factory::template create<sinks::syslog_sink_mt>(logger_name, syslog_ident, syslog_option, syslog_facility,
|
return Factory::template create<sinks::syslog_sink_mt>(logger_name, syslog_ident, syslog_option,
|
||||||
enable_formatting);
|
syslog_facility, enable_formatting);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Factory = spdlog::synchronous_factory>
|
template <typename Factory = spdlog::synchronous_factory>
|
||||||
@ -98,7 +98,7 @@ inline std::shared_ptr<logger> syslog_logger_st(const std::string &logger_name,
|
|||||||
int syslog_option = 0,
|
int syslog_option = 0,
|
||||||
int syslog_facility = LOG_USER,
|
int syslog_facility = LOG_USER,
|
||||||
bool enable_formatting = false) {
|
bool enable_formatting = false) {
|
||||||
return Factory::template create<sinks::syslog_sink_st>(logger_name, syslog_ident, syslog_option, syslog_facility,
|
return Factory::template create<sinks::syslog_sink_st>(logger_name, syslog_ident, syslog_option,
|
||||||
enable_formatting);
|
syslog_facility, enable_formatting);
|
||||||
}
|
}
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
Loading…
Reference in New Issue
Block a user