Optimizations:
In this example, all output will be written to the console, debug window, and "out.txt" file. It will be:
00001 [1] this is so cool 1 00002 [2] this is so cool again 2 00003 [3] hello, world 00004 [4] good to be back ;) 3
00001 00034 #include <boost/logging/format_fwd.hpp> 00035 00036 #include <boost/logging/format/named_write.hpp> 00037 typedef boost::logging::named_logger<>::type logger_type; 00038 00039 #define L_ BOOST_LOG_USE_LOG_IF_FILTER(g_l(), g_log_filter()->is_enabled() ) 00040 00041 // Define the filters and loggers you'll use (usually in a source file) 00042 BOOST_DEFINE_LOG_FILTER(g_log_filter, boost::logging::filter::no_ts ) 00043 BOOST_DEFINE_LOG(g_l, logger_type) 00044 00045 00046 void one_logger_one_filter_example() { 00047 // formatting : [idx] message \n 00048 // destinations : console, file "out.txt" and debug window 00049 g_l()->writer().write("[%idx%] |\n", "cout file(out.txt) debug"); 00050 g_l()->mark_as_initialized(); 00051 00052 int i = 1; 00053 L_ << "this is so cool " << i++; 00054 L_ << "this is so cool again " << i++; 00055 00056 std::string hello = "hello", world = "world"; 00057 L_ << hello << ", " << world; 00058 00059 g_log_filter()->set_enabled(false); 00060 L_ << "this will not be written to the log"; 00061 L_ << "this won't be written to the log"; 00062 00063 g_log_filter()->set_enabled(true); 00064 L_ << "good to be back ;) " << i++; 00065 } 00066 00067 00068 00069 00070 int main() { 00071 one_logger_one_filter_example(); 00072 } 00073 00074 00075 // End of file 00076