auto flush in boost syslog sink backend (boost 1.59)

谁说我不能喝 提交于 2019-12-11 16:50:42

问题


Is there any method to flush() in syslog backend. I am facing issue with boost syslog sink, after 6 log messages the 7th message is not getting logged into syslog (stays in buffer) until new log message is called.

My syslog implementation:

 typedef sinks::synchronous_sink< sinks::syslog_backend > sink_t;
    boost::shared_ptr< sink_t > syslogSink(
            new sink_t(
            keywords::facility = sinks::syslog::local0,
            keywords::use_impl = sinks::syslog::native
    ));
   sinks::syslog::custom_severity_mapping< std::string > mapping("severityLevel");
        mapping["debug"] = sinks::syslog::debug;
        mapping["info"] = sinks::syslog::info;
        mapping["notice"] = sinks::syslog::info;
        mapping["warning"] = sinks::syslog::warning;
        mapping["error"] = sinks::syslog::error;
        mapping["critical"] = sinks::syslog::critical;
        syslogSink->locked_backend()->set_severity_mapper(mapping);
        syslogSink->locked_backend()->auto_flush(m_logAutoFlush);
        logging::formatter formatter = CEFFormat();
        syslogSink->set_formatter(formatter);
        syslogSink->set_filter(expr::attr<std::string>("Channel") == "signatureID");
        logging::core::get()->add_sink(syslogSink);

syslogSink->flush();

I tried using flush() method as per http://www.boost.org/doc/libs/1_59_0/libs/log/doc/html/boost/log/sinks/synchronous_sink.html#idp54313520-bb

but it didn't help and still log messages are not logged in time by staying in buffer.


回答1:


There is no auto_flush method for the syslog backend in Boost.Log because the backend doesn't buffer formatted records. The flush method for this backend in conjunction with the synchronous_sink frontend is basically a no-op and provided for interface unification across all sinks.

Since you're using the native syslog implementation, you should have a look at how your syslog daemon operates and if there is any way to force it flush its internal buffers. This cannot be done from Boost.Log side.



来源:https://stackoverflow.com/questions/34654577/auto-flush-in-boost-syslog-sink-backend-boost-1-59

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!