| 1 | #define BOOST_LOG_DYN_LINK
|
|---|
| 2 | #define BOOST_LOG_USE_NATIVE_SYSLOG
|
|---|
| 3 |
|
|---|
| 4 | #include <boost/log/core.hpp>
|
|---|
| 5 | #include <boost/log/sources/logger.hpp>
|
|---|
| 6 |
|
|---|
| 7 | #include <boost/smart_ptr/shared_ptr.hpp>
|
|---|
| 8 | #include <boost/log/common.hpp>
|
|---|
| 9 | #include <boost/log/sinks/sync_frontend.hpp>
|
|---|
| 10 | #include <boost/log/sinks/syslog_backend.hpp>
|
|---|
| 11 |
|
|---|
| 12 | // Complete sink type
|
|---|
| 13 | typedef boost::log::sinks::synchronous_sink< boost::log::sinks::syslog_backend > sink_t;
|
|---|
| 14 |
|
|---|
| 15 | namespace logging = boost::log;
|
|---|
| 16 | namespace sinks = boost::log::sinks;
|
|---|
| 17 | namespace keywords = boost::log::keywords;
|
|---|
| 18 | namespace sources = boost::log::sources;
|
|---|
| 19 |
|
|---|
| 20 | void init_native_syslog()
|
|---|
| 21 | {
|
|---|
| 22 | boost::shared_ptr< logging::core > core = logging::core::get();
|
|---|
| 23 |
|
|---|
| 24 | // Create a backend
|
|---|
| 25 | boost::shared_ptr< sinks::syslog_backend > backend(new sinks::syslog_backend(
|
|---|
| 26 | keywords::facility = sinks::syslog::user,
|
|---|
| 27 | keywords::use_impl = sinks::syslog::native
|
|---|
| 28 | ));
|
|---|
| 29 |
|
|---|
| 30 | // Set the straightforward level translator for the "Severity" attribute of type int
|
|---|
| 31 | backend->set_severity_mapper(sinks::syslog::direct_severity_mapping< int >("Severity"));
|
|---|
| 32 |
|
|---|
| 33 | // Wrap it into the frontend and register in the core.
|
|---|
| 34 | // The backend requires synchronization in the frontend.
|
|---|
| 35 | core->add_sink(boost::make_shared< sink_t >(backend));
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | int main(int argc, char** argv) {
|
|---|
| 39 |
|
|---|
| 40 | init_native_syslog();
|
|---|
| 41 |
|
|---|
| 42 | sources::logger logger;
|
|---|
| 43 | BOOST_LOG(logger) << "TEST_SYSLOG";
|
|---|
| 44 |
|
|---|
| 45 | return 0;
|
|---|
| 46 | }
|
|---|