1 /* 2 * Copyright Andrey Semashev 2007 - 2015. 3 * Distributed under the Boost Software License, Version 1.0. 4 * (See accompanying file LICENSE_1_0.txt or copy at 5 * http://www.boost.org/LICENSE_1_0.txt) 6 */ 7 8 #include <boost/smart_ptr/shared_ptr.hpp> 9 #include <boost/log/core.hpp> 10 #include <boost/log/expressions/predicates/is_debugger_present.hpp> 11 #include <boost/log/sinks/sync_frontend.hpp> 12 #include <boost/log/sinks/debug_output_backend.hpp> 13 #include <boost/log/sources/logger.hpp> 14 #include <boost/log/sources/record_ostream.hpp> 15 16 #if defined(BOOST_WINDOWS) 17 18 namespace logging = boost::log; 19 namespace expr = boost::log::expressions; 20 namespace src = boost::log::sources; 21 namespace sinks = boost::log::sinks; 22 23 //[ example_sinks_debugger 24 // Complete sink type 25 typedef sinks::synchronous_sink< sinks::debug_output_backend > sink_t; 26 init_logging()27void init_logging() 28 { 29 boost::shared_ptr< logging::core > core = logging::core::get(); 30 31 // Create the sink. The backend requires synchronization in the frontend. 32 boost::shared_ptr< sink_t > sink(new sink_t()); 33 34 // Set the special filter to the frontend 35 // in order to skip the sink when no debugger is available 36 sink->set_filter(expr::is_debugger_present()); 37 38 core->add_sink(sink); 39 } 40 //] 41 main(int,char * [])42int main(int, char*[]) 43 { 44 init_logging(); 45 46 src::logger lg; 47 BOOST_LOG(lg) << "Hello world!"; 48 49 return 0; 50 } 51 52 #else 53 main(int,char * [])54int main(int, char*[]) 55 { 56 return 0; 57 } 58 59 #endif 60