fastest_use_ostr_like.cpp

This usage:

Here's what the output will be:

The console:

00001 this is so cool 1
00002 this is so cool again 2
00003 hello, world
00004 good to be back ;) 4

The err.txt file:

00001 first error 3
00002 second error 5

00001 
00038 #define BOOST_LOG_COMPILE_FAST_OFF
00039 #include <boost/logging/logging.hpp>
00040 #include <boost/logging/format.hpp>
00041 
00042 using namespace boost::logging;
00043 
00044 typedef logger< default_, destination::cout> app_log_type;
00045 typedef logger< default_, destination::file> err_log_type;
00046 
00047 BOOST_DEFINE_LOG_FILTER(g_log_filter, filter::no_ts )
00048 
00049 BOOST_DEFINE_LOG(g_log_app, app_log_type )
00050 BOOST_DEFINE_LOG_WITH_ARGS( g_log_err, err_log_type, ("err.txt") )
00051 
00052 #define LAPP_ BOOST_LOG_USE_LOG_IF_FILTER(g_log_app(), g_log_filter()->is_enabled() ) 
00053 #define LERR_ BOOST_LOG_USE_LOG_IF_FILTER(g_log_err(), g_log_filter()->is_enabled() ) 
00054 
00055 void fastest_use_ostr_like_example() {
00056     g_log_app()->mark_as_initialized();
00057     g_log_err()->mark_as_initialized();
00058 
00059     int i = 1;
00060     LAPP_ << "this is so cool " << i++ << "\n";
00061     LAPP_ << "this is so cool again " << i++ << "\n";
00062     LERR_ << "first error " << i++ << "\n";
00063 
00064     std::string hello = "hello", world = "world";
00065     LAPP_ << hello << ", " << world << "\n";
00066 
00067     g_log_filter()->set_enabled(false);
00068     LAPP_ << "this will not be written to the log";
00069     LAPP_ << "this won't be written to the log";
00070     LERR_ << "this error is not logged " << i++;
00071 
00072     g_log_filter()->set_enabled(true);
00073     LAPP_ << "good to be back ;) " << i++ << "\n";
00074     LERR_ << "second error " << i++ << "\n";
00075 }
00076 
00077 
00078 
00079 
00080 int main() {
00081     fastest_use_ostr_like_example();
00082 }
00083 
00084 
00085 // End of file
00086 


Copyright John Torjo © 2007
Have a question/ suggestion/ comment? Send me feedback