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:
Here's what the output will be:
The console:
The err.txt file:
00001 00052 #define BOOST_LOG_COMPILE_FAST_OFF 00053 #include <boost/logging/logging.hpp> 00054 #include <boost/logging/format.hpp> 00055 00056 using namespace boost::logging; 00057 00058 struct no_gather { 00059 typedef const char* msg_type ; 00060 const char * m_msg; 00061 no_gather() : m_msg(0) {} 00062 const char * msg() const { return m_msg; } 00063 void *out(const char* msg) { m_msg = msg; return this; } 00064 void *out(const std::string& msg) { m_msg = msg.c_str(); return this; } 00065 }; 00066 00067 00068 typedef logger< no_gather, destination::cout > app_log_type; 00069 typedef logger< no_gather, destination::file > err_log_type; 00070 00071 BOOST_DEFINE_LOG_FILTER(g_log_filter, filter::no_ts ) 00072 00073 BOOST_DEFINE_LOG(g_log_app, app_log_type) 00074 BOOST_DEFINE_LOG_WITH_ARGS( g_log_err, err_log_type, ("err.txt") ) 00075 00076 #define LAPP_ BOOST_LOG_USE_SIMPLE_LOG_IF_FILTER(g_log_app(), g_log_filter()->is_enabled() ) 00077 #define LERR_ BOOST_LOG_USE_SIMPLE_LOG_IF_FILTER(g_log_err(), g_log_filter()->is_enabled() ) 00078 00079 void fastest_no_ostr_like_example() { 00080 g_log_app()->mark_as_initialized(); 00081 g_log_err()->mark_as_initialized(); 00082 00083 LAPP_("this is so cool\n"); 00084 LERR_("first error \n"); 00085 00086 std::string hello = "hello", world = "world"; 00087 LAPP_(hello + ", " + world + "\n"); 00088 00089 g_log_filter()->set_enabled(false); 00090 LAPP_("this will not be written to the log"); 00091 LAPP_("this won't be written to the log"); 00092 LERR_("this error is not logged "); 00093 00094 g_log_filter()->set_enabled(true); 00095 LAPP_("good to be back ;) \n" ); 00096 LERR_("second error \n" ); 00097 } 00098 00099 00100 00101 00102 int main() { 00103 fastest_no_ostr_like_example(); 00104 } 00105 00106 00107 // End of file 00108