Boost syslog to a specific file using syslog sink

问题内容:

Is it possible to configure boost log to send logs to a specific file when using the syslog backend on debian9. The following code initializes my logging sink:

namespace logging = boost::log;
namespace sinks = boost::log::sinks;
namespace keywords = boost::log::keywords;
using namespace boost::log::sinks::syslog;

boost::shared_ptr< logging::core > core = logging::core::get();

boost::shared_ptr< sinks::syslog_backend > backend =
    boost::make_shared< sinks::syslog_backend >(
        keywords::use_impl = sinks::syslog::udp_socket_based,
        keywords::facility = sinks::syslog::local0
    );


// Create and fill in another level translator for "MyLevel" attribute of type string
sinks::syslog::custom_severity_mapping< std::string > mapping("MyLevel");
mapping["debug"] = sinks::syslog::debug;
mapping["info"] = sinks::syslog::info;
mapping["warning"] = sinks::syslog::warning;
mapping["error"] = sinks::syslog::error;
backend->set_severity_mapper(mapping);
backend->set_target_address("localhost");

// Wrap it into the frontend and register in the core.
// The backend requires synchronization in the frontend.
typedef sinks::synchronous_sink< sinks::syslog_backend > sink_t;
boost::shared_ptr< sink_t > sink(new sink_t(backend));

core->add_sink(sink);

问题评论:

原文地址:

https://stackoverflow.com/questions/47755287/boost-syslog-to-a-specific-file-using-syslog-sink

添加评论