// boostLogger.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include #include #include #include #include // logging::trivial::severity #include #include #include #include #include #include #include namespace logging = boost::log; namespace src = boost::log::sources; namespace keywords = boost::log::keywords; namespace sinks = boost::log::sinks; namespace attrs = boost::log::attributes; namespace expr = boost::log::expressions; static const unsigned int myWidth = 5; static const unsigned int headerWidth = 10; src::severity_logger_mt< logging::trivial::severity_level > lg; logging::trivial::severity_level mySev; void logGEMM( int m, int n, int k ) { lg.add_attribute( "M", attrs::constant< int >( m ) ); lg.add_attribute( "N", attrs::constant< int >( n ) ); lg.add_attribute( "K", attrs::constant< int >( k ) ); BOOST_LOG_SEV( lg, logging::trivial::trace ); lg.remove_all_attributes( ); } int _tmain(int argc, _TCHAR* argv[]) { typedef sinks::synchronous_sink< sinks::text_ostream_backend > text_sink; boost::shared_ptr< text_sink > sink = boost::make_shared< text_sink >( ); boost::shared_ptr< std::ostream > stream( &std::clog, boost::empty_deleter( ) ); sink->locked_backend( )->add_stream( stream ); boost::shared_ptr< logging::core > core = logging::core::get( ); // BUG: This set_filter call affects the behavior of remove_all_attributes // BUG: Comment this out for correct logging behavior core->set_filter( logging::trivial::severity >= logging::trivial::trace ); core->add_sink( sink ); sink->set_formatter( expr::stream << std::setw( myWidth ) << "[ " << expr::attr< int >( "M" ) << " ] " << std::setw( myWidth ) << "[ " << expr::attr< int >( "N" ) << " ] " << std::setw( myWidth ) << "[ " << expr::attr< int >( "K" ) << " ] " << expr::smessage ); float tmp = 1.0f; logGEMM( 1, 2, 3 ); logGEMM( 4, 5, 6 ); logGEMM( 7, 8, 9 ); return 0; }