Ticket #10242: boostLogger.cpp

File boostLogger.cpp, 2.5 KB (added by Kent Knox <kent.knox@…>, 8 years ago)

Notice the comments tagged with BUG

Line 
1// boostLogger.cpp : Defines the entry point for the console application.
2//
3
4#include "stdafx.h"
5#include <stdio.h>
6#include <tchar.h>
7#include <fstream>
8#include <iomanip>
9
10#include <boost/log/trivial.hpp>
11#include <boost/log/core.hpp>
12#include <boost/log/expressions.hpp> // logging::trivial::severity
13#include <boost/log/sinks/sync_frontend.hpp>
14#include <boost/log/sinks/text_ostream_backend.hpp>
15#include <boost/log/sources/severity_logger.hpp>
16#include <boost/log/sources/severity_feature.hpp>
17
18#include <boost/log/attributes/constant.hpp>
19
20#include <boost/smart_ptr/shared_ptr.hpp>
21#include <boost/utility/empty_deleter.hpp>
22
23namespace logging = boost::log;
24namespace src = boost::log::sources;
25namespace keywords = boost::log::keywords;
26namespace sinks = boost::log::sinks;
27
28namespace attrs = boost::log::attributes;
29namespace expr = boost::log::expressions;
30
31static const unsigned int myWidth = 5;
32static const unsigned int headerWidth = 10;
33
34src::severity_logger_mt< logging::trivial::severity_level > lg;
35logging::trivial::severity_level mySev;
36
37void logGEMM( int m, int n, int k )
38{
39 lg.add_attribute( "M", attrs::constant< int >( m ) );
40 lg.add_attribute( "N", attrs::constant< int >( n ) );
41 lg.add_attribute( "K", attrs::constant< int >( k ) );
42
43 BOOST_LOG_SEV( lg, logging::trivial::trace );
44
45 lg.remove_all_attributes( );
46}
47
48int _tmain(int argc, _TCHAR* argv[])
49{
50 typedef sinks::synchronous_sink< sinks::text_ostream_backend > text_sink;
51 boost::shared_ptr< text_sink > sink = boost::make_shared< text_sink >( );
52
53 boost::shared_ptr< std::ostream > stream( &std::clog, boost::empty_deleter( ) );
54 sink->locked_backend( )->add_stream( stream );
55
56 boost::shared_ptr< logging::core > core = logging::core::get( );
57
58 // BUG: This set_filter call affects the behavior of remove_all_attributes
59 // BUG: Comment this out for correct logging behavior
60 core->set_filter( logging::trivial::severity >= logging::trivial::trace );
61
62 core->add_sink( sink );
63
64 sink->set_formatter( expr::stream
65 << std::setw( myWidth ) << "[ " << expr::attr< int >( "M" ) << " ] "
66 << std::setw( myWidth ) << "[ " << expr::attr< int >( "N" ) << " ] "
67 << std::setw( myWidth ) << "[ " << expr::attr< int >( "K" ) << " ] "
68 << expr::smessage );
69
70 float tmp = 1.0f;
71
72 logGEMM( 1, 2, 3 );
73 logGEMM( 4, 5, 6 );
74 logGEMM( 7, 8, 9 );
75
76 return 0;
77}