Author: John Torjo, www.torjo.com
Copyright (C) 2007 John Torjo (see www.torjo.com for email)
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
See http://www.boost.org for updates, documentation, and revision history. See http://www.torjo.com/log2/ for more details
This usage:
In this example, all output will be written to the console, debug output window, and "out.txt" file. It will look similar to this one:
00001 21:03.17.243 [1] this is so cool 1 00002 21:03.17.243 [2] first error 2 00003 21:03.17.243 [3] hello, world 00004 21:03.17.243 [4] second error 3 00005 21:03.17.243 [5] good to be back ;) 4 00006 21:03.17.243 [6] third error 5
00001 00045 #include <boost/logging/format/named_write.hpp> 00046 typedef boost::logging::named_logger<>::type logger_type; 00047 00048 #define L_(lvl) BOOST_LOG_USE_LOG_IF_LEVEL(g_l(), g_log_level(), lvl ) 00049 00050 BOOST_DEFINE_LOG_FILTER(g_log_level, boost::logging::level::holder ) // holds the application log level 00051 BOOST_DEFINE_LOG(g_l, logger_type) 00052 00053 void test_mul_levels_one_logger() { 00054 // formatting : time [idx] message \n 00055 // destinations : console, file "out.txt" and debug window 00056 g_l()->writer().write("%time%($hh:$mm.$ss.$mili) [%idx%] |\n", "cout file(out.txt) debug"); 00057 g_l()->mark_as_initialized(); 00058 00059 int i = 1; 00060 L_(debug) << "this is so cool " << i++; 00061 L_(error) << "first error " << i++; 00062 00063 std::string hello = "hello", world = "world"; 00064 L_(debug) << hello << ", " << world; 00065 00066 using namespace boost::logging; 00067 g_log_level()->set_enabled(level::error); 00068 L_(debug) << "this will not be written anywhere"; 00069 L_(info) << "this won't be written anywhere either"; 00070 L_(error) << "second error " << i++; 00071 00072 g_log_level()->set_enabled(level::info); 00073 L_(info) << "good to be back ;) " << i++; 00074 L_(error) << "third error " << i++; 00075 } 00076 00077 00078 00079 int main() { 00080 test_mul_levels_one_logger(); 00081 } 00082 00083 00084 // End of file 00085