Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2008-01-04 10:52:58


Author: jtorjo
Date: 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
New Revision: 42454
URL: http://svn.boost.org/trac/boost/changeset/42454

Log:
[logging]
v0.13.2, 4 jan 2008
- breaks compilation on gcc4.1
- can cache messages before initialization of logs
Added:
   sandbox/logging/lib/logging/samples/scenarios/cache_before_init.cpp (contents, props changed)
Text files modified:
   sandbox/logging/boost/logging/detail/cache_before_init.hpp | 51 +++++++++++++++-------
   sandbox/logging/boost/logging/detail/cache_before_init_macros.hpp | 5 +
   sandbox/logging/boost/logging/detail/logger.hpp | 87 +++++++++++++++++++++++++++++++++------
   sandbox/logging/boost/logging/detail/macros.hpp | 4
   sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp | 2
   sandbox/logging/boost/logging/detail/raw_doc/todo.hpp | 2
   sandbox/logging/lib/logging/internal/vc8/loggingvc8/loggingvc8.vcproj | 5 ++
   sandbox/logging/lib/logging/internal/vc8/loggingvc8/test_now.cpp | 12 -----
   sandbox/logging/lib/logging/samples/scenarios/custom_fmt_dest.cpp | 1
   sandbox/logging/lib/logging/samples/scenarios/ded_loger_one_filter.cpp | 1
   sandbox/logging/lib/logging/samples/scenarios/fastest_no_ostr_like.cpp | 4 +
   sandbox/logging/lib/logging/samples/scenarios/fastest_use_ostr_like.cpp | 3 +
   sandbox/logging/lib/logging/samples/scenarios/mul_levels_mul_logers.cpp | 4 +
   sandbox/logging/lib/logging/samples/scenarios/mul_levels_one_logger.cpp | 2
   sandbox/logging/lib/logging/samples/scenarios/mul_loggers_one_filter.cpp | 4 +
   sandbox/logging/lib/logging/samples/scenarios/no_levels_with_route.cpp | 2
   sandbox/logging/lib/logging/samples/scenarios/one_loger_one_filter.cpp | 2
   sandbox/logging/lib/logging/samples/scenarios/ts_loger_one_filter.cpp | 1
   sandbox/logging/lib/logging/samples/scenarios/use_tss_ostringstream.cpp | 11 ----
   sandbox/logging/lib/logging/samples/scenarios/using_tags.cpp | 1
   sandbox/logging/lib/logging/samples/scenarios/your_scenario.cpp | 3 +
   21 files changed, 149 insertions(+), 58 deletions(-)

Modified: sandbox/logging/boost/logging/detail/cache_before_init.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/cache_before_init.hpp (original)
+++ sandbox/logging/boost/logging/detail/cache_before_init.hpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -51,6 +51,9 @@
 #endif
 }
 
+#ifndef BOOST_LOG_BEFORE_INIT_LOCK_RESOURCE_CLASS
+#define BOOST_LOG_BEFORE_INIT_LOCK_RESOURCE_CLASS ::boost::logging::lock_resource_finder::single_thread
+#endif
 
 #if defined( BOOST_LOG_BEFORE_INIT_USE_CACHE_FILTER) || defined( BOOST_LOG_BEFORE_INIT_USE_LOG_ALL)
 //////////////////////////////////////////////////////////////////
@@ -66,7 +69,7 @@
 
 
 */
-template<class msg_type, class lock_resource = ::boost::logging::lock_resource_finder::single_thread > struct cache_before_init {
+template<class msg_type, class lock_resource = BOOST_LOG_BEFORE_INIT_LOCK_RESOURCE_CLASS > struct cache_before_init {
 private:
     typedef typename lock_resource::template finder<bool>::type is_cache_enabled_data;
     typedef bool (*is_enabled_func)();
@@ -106,11 +109,13 @@
 
         // now we go the slow way - use mutex to see if cache is turned off
         mutex::scoped_lock lk(m_cs);
- return !(m_cache.is_using_cache);
+ return (m_cache.is_using_cache);
     }
 
-protected:
- template<class self_type> void turn_cache_off(self_type & self) {
+ template<class writer_type> void turn_cache_off(writer_type & writer) {
+ if ( !is_cache_turned_on() )
+ return; // already turned off
+
         {
         mutex::scoped_lock lk(m_cs);
         m_cache.is_using_cache = false;
@@ -122,14 +127,19 @@
         }
 
         // dump messages
- cache::message_array msgs;
+ typename cache::message_array msgs;
         {
         mutex::scoped_lock lk(m_cs);
         std::swap( m_cache.msgs, msgs);
         }
- for ( cache::message_array::const_iterator b = msgs.begin(), e = msgs.end(); b != e; ++b)
- if ( b->is_enabled() )
- self( b->string );
+ for ( typename cache::message_array::iterator b = msgs.begin(), e = msgs.end(); b != e; ++b) {
+ if ( !(b->is_enabled) )
+ // no filter
+ writer( b->string );
+ else if ( b->is_enabled() )
+ // filter enabled
+ writer( b->string );
+ }
     }
 
     // called after all data has been gathered
@@ -140,6 +150,13 @@
             writer(msg);
     }
 
+protected:
+ void add_msg(const msg_type & msg) const {
+ mutex::scoped_lock lk(m_cs);
+ // note : last_enabled can be null, if we don't want to use filters (BOOST_LOG_BEFORE_INIT_USE_LOG_ALL)
+ is_enabled_func func = m_cache.threads[ get_thread_id() ].last_enabled ;
+ m_cache.msgs.push_back( message(func, msg) );
+ }
 
 public:
     void set_callback(is_enabled_func f) {
@@ -147,20 +164,14 @@
         m_cache.threads[ get_thread_id() ].last_enabled = f;
     }
 
- void add_msg(const msg_type & msg) {
- mutex::scoped_lock lk(m_cs);
- // note : last_enabled can be null, if we don't want to use filters (BOOST_LOG_BEFORE_INIT_USE_LOG_ALL)
- is_enabled_func func = m_cache.threads[ get_thread_id() ].last_enabled ;
- m_cache.msgs.push_back( message(func, msg) );
- }
 
 
 
 
 
 private:
- mutex m_cs;
- cache m_cache;
+ mutable mutex m_cs;
+ mutable cache m_cache;
     /**
     IMPORTANT: to make sure we know when the cache is off as efficiently as possible, I have this mechanism:
     - first, query m_is_enabled,which at the beginning is false (this is very efficient, we can use TSS here)
@@ -179,7 +190,13 @@
 //////////////////////////////////////////////////////////////////
 // Messages that were logged before initializing the log - NOT Caching them
 
-template<class msg_type, class lock_resource = ::boost::logging::lock_resource_finder::single_thread > struct cache_before_init {
+template<class msg_type, class lock_resource = BOOST_LOG_BEFORE_INIT_LOCK_RESOURCE_CLASS > struct cache_before_init {
+ template<class writer_type> void on_do_write(msg_type & msg, const writer_type & writer) const {
+ writer(msg);
+ }
+
+ template<class writer_type> void turn_cache_off(writer_type & writer) {
+ }
 
 };
 

Modified: sandbox/logging/boost/logging/detail/cache_before_init_macros.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/cache_before_init_macros.hpp (original)
+++ sandbox/logging/boost/logging/detail/cache_before_init_macros.hpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -55,11 +55,11 @@
                 set_callback_if_needed(); \
         } \
         void set_callback_if_needed() { \
+ if ( l .base()->cache().is_cache_turned_on() ) \
+ l .base()->cache().set_callback( &is_enabled_callback ); \
         } \
     } param_name = ( !(is_log_enabled) ) ? (void*)0 : l .base()-> do_func
 
-// if ( l.is_cache_turned_on() ) \
- // l.set_callback( &is_enabled_callback ); \
 
 #define BOOST_LOG_USE_LOG(l, do_func, is_log_enabled) \
     BOOST_LOG_USE_LOG_LOCAL_CLASS( l, do_func, is_log_enabled, \
@@ -70,6 +70,7 @@
 /////////////////////////////////////////////////////////////////////////////////////////////
 // Messages that were logged before initializing the log - cache the message (and I'll write it even if the filter is turned off)
 
+#define BOOST_LOG_USE_LOG(l, do_func, is_log_enabled) if ( !(is_log_enabled) ) ; else l .base()-> do_func
 
 #elif defined( BOOST_LOG_BEFORE_INIT_USE_IGNORE_BEFORE_INIT)
 /////////////////////////////////////////////////////////////////////////////////////////////

Modified: sandbox/logging/boost/logging/detail/logger.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/logger.hpp (original)
+++ sandbox/logging/boost/logging/detail/logger.hpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -24,6 +24,7 @@
 #include <boost/logging/detail/fwd.hpp>
 #include <boost/logging/detail/forward_constructor.hpp>
 #include <boost/logging/detail/find_gather.hpp>
+#include <boost/logging/detail/cache_before_init.hpp>
 
 namespace boost { namespace logging {
 
@@ -50,6 +51,12 @@
 
     namespace detail {
         template<class type> type& as_non_const(const type & t) { return const_cast<type&>(t); }
+
+ template<class gather_msg> struct find_gather_if_default {
+ typedef typename use_default<gather_msg,
+ gather::ostream_like::return_str< std::basic_string<char_type>, std::basic_ostringstream<char_type> > > ::type gather_type;
+ typedef typename gather_type::msg_type msg_type;
+ };
     }
 
 
@@ -109,14 +116,20 @@
     
     */
     template<class gather_msg = default_, class write_msg = default_ > struct logger {
- typedef typename use_default<gather_msg, gather::ostream_like::return_str< std::basic_string<char_type>, std::basic_ostringstream<char_type> > > ::type gather_type;
+ typedef typename detail::find_gather_if_default<gather_msg>::gather_type gather_type;
         typedef write_msg write_type;
+ typedef detail::cache_before_init<typename detail::find_gather_if_default<gather_msg>::msg_type > cache_type;
 
         typedef logger<gather_msg, write_msg> self;
 
         logger() {}
         BOOST_LOGGING_FORWARD_CONSTRUCTOR(logger,m_writer)
 
+ ~logger() {
+ // force writing all messages from cache, if cache hasn't been turned off yet
+ turn_cache_off();
+ }
+
         /**
             reads all data about a log message (gathers all the data about it)
         */
@@ -125,79 +138,119 @@
         write_msg & writer() { return m_writer; }
         const write_msg & writer() const { return m_writer; }
 
+ cache_type & cache() { return m_cache; }
+ const cache_type & cache() const { return m_cache; }
+
         // called after all data has been gathered
         void on_do_write(gather_type & gather) const {
- m_writer( detail::as_non_const(gather.msg()) );
+ cache().on_do_write( detail::as_non_const(gather.msg()), writer() );
+ }
+ void turn_cache_off() {
+ cache().turn_cache_off( writer() );
         }
 
     private:
         write_msg m_writer;
+ cache_type m_cache;
     };
 
     // specialize for write_msg* pointer!
     template<class gather_msg, class write_msg> struct logger<gather_msg, write_msg* > {
- typedef gather_msg gather_type;
+ typedef typename detail::find_gather_if_default<gather_msg>::gather_type gather_type;
+ typedef detail::cache_before_init<typename detail::find_gather_if_default<gather_msg>::msg_type > cache_type;
         typedef write_msg write_type;
 
         typedef logger<gather_msg, write_msg*> self;
 
- logger(write_msg * writer = 0) : m_writer(writer) {}
+ logger(write_msg * writer = 0) : m_writer(writer) {
+ }
+ ~logger() {
+ // force writing all messages from cache, if cache hasn't been turned off yet
+ turn_cache_off();
+ }
 
         void set_writer(write_msg* writer) {
             m_writer = writer;
         }
 
- // FIXME watch for copy-construction!
         /**
             reads all data about a log message (gathers all the data about it)
- FIXME
         */
         gather_holder<self, gather_msg> read_msg() const { return gather_holder<self, gather_msg>(*this) ; }
 
         write_msg & writer() { return *m_writer; }
         const write_msg & writer() const { return *m_writer; }
 
+ cache_type & cache() { return m_cache; }
+ const cache_type & cache() const { return m_cache; }
+
         // called after all data has been gathered
         void on_do_write(gather_msg & gather) const {
- (*m_writer)( detail::as_non_const(gather.msg()) );
+ cache().on_do_write( detail::as_non_const(gather.msg()), writer() );
+ }
+ void turn_cache_off() {
+ cache().turn_cache_off( writer() );
         }
 
     private:
         write_msg *m_writer;
+ cache_type m_cache;
     };
 
 
     // specialize when write_msg is not set - in this case, you need to derive from this
     template<class gather_msg> struct logger<gather_msg, default_ > {
- typedef gather_msg gather_type;
+ typedef typename detail::find_gather_if_default<gather_msg>::gather_type gather_type;
+ typedef detail::cache_before_init<typename detail::find_gather_if_default<gather_msg>::msg_type > cache_type;
         typedef void_ write_type;
 
         typedef logger<gather_msg, default_> self;
         typedef typename gather_msg::msg_type msg_type;
 
- logger() {}
+ logger() : m_cache(0) {}
         // we have virtual functions, lets have a virtual destructor as well - many thanks Martin Baeker!
- virtual ~logger() {}
+ virtual ~logger() {
+ // force writing all messages from cache, if cache hasn't been turned off yet
+ turn_cache_off();
+ }
 
- // FIXME watch for copy-construction!
         /**
             reads all data about a log message (gathers all the data about it)
- FIXME
         */
         gather_holder<self, gather_msg> read_msg() const { return gather_holder<self, gather_msg>(*this) ; }
 
         write_type & writer() { return m_writer; }
         const write_type & writer() const { return m_writer; }
 
+ cache_type & cache() { return *m_cache; }
+ const cache_type & cache() const { return *m_cache; }
+
+ void set_cache(cache_type * cache_) {
+ m_cache = cache_;
+ }
+
+ private:
+ struct call_do_write {
+ const logger & self;
+ call_do_write(const logger & self) : self(self) {}
+ void operator()(msg_type & msg) const {
+ self.do_write(msg);
+ }
+ };
+ public:
         // called after all data has been gathered
         void on_do_write(gather_msg & gather) const {
- do_write( detail::as_non_const(gather.msg()) );
+ cache().on_do_write( detail::as_non_const(gather.msg()), call_do_write(*this) );
+ }
+ void turn_cache_off() {
+ cache().turn_cache_off( call_do_write(*this) );
         }
 
         virtual void do_write(msg_type&) const = 0;
     private:
         // we don't know the writer
         void_ m_writer;
+ cache_type *m_cache;
     };
 
     /**
@@ -221,12 +274,16 @@
     // specialization for pointers
     template<class gather_msg, class write_msg> struct implement_default_logger<gather_msg,write_msg*> : logger<gather_msg, default_> {
         typedef typename gather_msg::msg_type msg_type;
+ typedef detail::cache_before_init<typename detail::find_gather_if_default<gather_msg>::msg_type > cache_type;
+ typedef logger<gather_msg, default_> log_base;
 
- implement_default_logger(write_msg * writer = 0) : m_writer(writer) {}
+ implement_default_logger(write_msg * writer = 0, cache_type * cache_ = 0) : m_writer(writer) {
+ log_base::set_cache( cache_);
+ }
 
         void set_writer(write_msg* writer) {
             m_writer = writer;
- }
+ }
 
         virtual void do_write(msg_type &a) const {
             (*m_writer)(a);

Modified: sandbox/logging/boost/logging/detail/macros.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/macros.hpp (original)
+++ sandbox/logging/boost/logging/detail/macros.hpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -514,7 +514,7 @@
     ::boost::logging::detail::fast_compile_with_default_gather<>::log_type & name ## _boost_log_impl_light_() \
     { typedef ::boost::logging::detail::fast_compile_with_default_gather<>::gather_msg gather_msg; \
     typedef type::write_type write_msg; \
- static ::boost::logging::implement_default_logger< gather_msg, write_msg* > p( &(name ## _boost_log_impl_().writer()) ); \
+ static ::boost::logging::implement_default_logger< gather_msg, write_msg* > p( &(name ## _boost_log_impl_().writer()), &(name ## _boost_log_impl_().cache()) ); \
     return p; } \
     namespace { boost::logging::detail::fake_using_log ensure_log_is_created_before_main ## name ( name ## _boost_log_impl_() ); } \
     boost::logging::detail::log_keeper<type, name ## _boost_log_impl_, ::boost::logging::detail::fast_compile_with_default_gather<>::log_type, name ## _boost_log_impl_light_ > name;
@@ -524,7 +524,7 @@
     ::boost::logging::detail::fast_compile_with_default_gather<>::log_type & name ## _boost_log_impl_light_() \
     { typedef ::boost::logging::detail::fast_compile_with_default_gather<>::gather_msg gather_msg; \
     typedef type::write_type write_msg; \
- static ::boost::logging::implement_default_logger< gather_msg, write_msg* > p( &(name ## _boost_log_impl_().writer()) ); \
+ static ::boost::logging::implement_default_logger< gather_msg, write_msg* > p( &(name ## _boost_log_impl_().writer()), &(name ## _boost_log_impl_().cache()) ); \
     return p; } \
     namespace { boost::logging::detail::fake_using_log ensure_log_is_created_before_main ## name ( name ## _boost_log_impl_() ); } \
     boost::logging::detail::log_keeper<type, name ## _boost_log_impl_, ::boost::logging::detail::fast_compile_with_default_gather<>::log_type, name ## _boost_log_impl_light_ > name;

Modified: sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -2,7 +2,7 @@
 @page page_changelog Changelog
 
 @section changelog_cur_ver Current Version: v0.13.1, 4 jan 2008
-- began implementation of caching messages before initialization of logs
+- can cache messages before initialization of logs
 - gather classes now have msg_type instead of param (msg_type contains the type of the returned msg - without const or &)
 
 v0.12.13, 29 dec 2007

Modified: sandbox/logging/boost/logging/detail/raw_doc/todo.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/todo.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/todo.hpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -22,6 +22,8 @@
 
 @section todo_implementation Implementation
 
+- @c high What should I do if someone is trying to use the log after it's been destroyed?
+
 - @c high Provide a Jamfile to build the examples/tests
 
 - @c high test TSS on vs2003 and gcc/pthreads \n

Modified: sandbox/logging/lib/logging/internal/vc8/loggingvc8/loggingvc8.vcproj
==============================================================================
--- sandbox/logging/lib/logging/internal/vc8/loggingvc8/loggingvc8.vcproj (original)
+++ sandbox/logging/lib/logging/internal/vc8/loggingvc8/loggingvc8.vcproj 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -330,6 +330,7 @@
>
                                 <FileConfiguration
                                         Name="Test|Win32"
+ ExcludedFromBuild="true"
>
                                         <Tool
                                                 Name="VCCLCompilerTool"
@@ -781,6 +782,10 @@
                         Name="scenarios"
>
                         <File
+ RelativePath="..\..\..\samples\scenarios\cache_before_init.cpp"
+ >
+ </File>
+ <File
                                 RelativePath="..\..\..\samples\scenarios\custom_fmt_dest.cpp"
>
                                 <FileConfiguration

Modified: sandbox/logging/lib/logging/internal/vc8/loggingvc8/test_now.cpp
==============================================================================
--- sandbox/logging/lib/logging/internal/vc8/loggingvc8/test_now.cpp (original)
+++ sandbox/logging/lib/logging/internal/vc8/loggingvc8/test_now.cpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -87,20 +87,10 @@
             .add( "debug", destination::dbg_window() )
             .add( "out", destination::file("out.txt"))
          );
+ g_l->turn_cache_off();
 
     // Step 8: use it...
     int i = 1;
-#if 0
- struct local_class {
- static bool is_enabled_callback() { return (g_log_filter->is_enabled()); }
- local_class (const void * p) {
- if ( p)
- set_callback_if_needed();
- }
- void set_callback_if_needed() {
- }
- } param_name = ( !(g_log_filter->is_enabled()) ) ? (void*)0 : g_l .base()-> read_msg().gather().out() << "this is so cool " << i++;
-#endif
 
     L_ << "this is so cool " << i++;
   // L_ << "this is so cool again " << i++;

Added: sandbox/logging/lib/logging/samples/scenarios/cache_before_init.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/samples/scenarios/cache_before_init.cpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -0,0 +1,155 @@
+/**
+@example cache_before_init.cpp
+
+@copydoc cache_before_init
+
+@page cache_before_init cache_before_init.cpp Example
+
+
+This usage:
+- You log a few messages before initializing the logs
+- You use one filter, based on levels
+- You specify a certain level for the filter, so that not all of the messages should be logged
+- You turn the cache off, and only those messages matching the filter are logged
+
+Optimizations:
+- use a cache string (from optimize namespace), in order to make formatting the message faster
+
+Logs:
+- Error messages go into err.txt file
+ - formatting - prefix each message by time, index, and append newline
+- Info output goes to console, and a file called out.txt
+ - formatting - prefix each message by "[app]", time, and append newline
+- Debug messages go to the debug output window, and a file called out.txt
+ - formatting - prefix each message by "[dbg]", time, and append newline
+
+
+Here's how the output will look like:
+
+The debug output window:
+@code
+17:29.41 [dbg] some debug message after logs have been initialized 11
+@endcode
+
+
+The console:
+@code
+17:29.41 [app] hello, world
+17:29.41 [app] coolio 4
+17:29.41 [app] after logs have been initialized 10
+@endcode
+
+
+The out.txt file:
+@code
+17:29.41 [app] hello, world
+17:29.41 [app] coolio 4
+17:29.41 [app] after logs have been initialized 10
+17:29.41 [dbg] some debug message after logs have been initialized 11
+@endcode
+
+
+The err.txt file
+@code
+17:29.41 [1] first error 3
+17:29.41 [2] second error 5
+@endcode
+*/
+
+
+
+// uncomment this, and all messages inside singleton's constructor will be logged!
+//#define BOOST_LOG_BEFORE_INIT_LOG_ALL
+
+// uncomment this, and NO messages inside singleton's constructor will be logged
+//#define BOOST_LOG_BEFORE_INIT_IGNORE_BEFORE_INIT
+
+#include <boost/logging/format_fwd.hpp>
+
+BOOST_LOG_FORMAT_MSG( optimize::cache_string_one_str<> )
+
+#include <boost/logging/format.hpp>
+#include <boost/logging/writer/ts_write.hpp>
+
+typedef boost::logging::logger_format_write< > log_type;
+
+
+BOOST_DECLARE_LOG_FILTER(g_log_level, boost::logging::level::holder ) // holds the application log level
+BOOST_DECLARE_LOG(g_log_err, log_type)
+BOOST_DECLARE_LOG(g_log_app, log_type)
+BOOST_DECLARE_LOG(g_log_dbg, log_type)
+
+#define LDBG_ BOOST_LOG_USE_LOG_IF_LEVEL(g_log_dbg, g_log_level, debug ) << "[dbg] "
+#define LERR_ BOOST_LOG_USE_LOG_IF_LEVEL(g_log_err, g_log_level, error )
+#define LAPP_ BOOST_LOG_USE_LOG_IF_LEVEL(g_log_app, g_log_level, info ) << "[app] "
+
+BOOST_DEFINE_LOG_FILTER(g_log_level, boost::logging::level::holder )
+BOOST_DEFINE_LOG(g_log_err, log_type)
+BOOST_DEFINE_LOG(g_log_app, log_type)
+BOOST_DEFINE_LOG(g_log_dbg, log_type)
+
+using namespace boost::logging;
+
+struct singleton {
+ singleton() {
+ // note: these messages are written before logs are initialized
+ int i = 1;
+ LDBG_ << "this is so cool " << i++;
+ LDBG_ << "this is so cool again " << i++;
+ LERR_ << "first error " << i++;
+
+ std::string hello = "hello", world = "world";
+ LAPP_ << hello << ", " << world;
+
+ LAPP_ << "coolio " << i++;
+ LERR_ << "second error " << i++;
+ LDBG_ << "some debug message" << i++;
+ }
+} s_;
+
+void init_logs() {
+ // Err log
+ g_log_err->writer().add_formatter( formatter::idx(), "[%] " );
+ g_log_err->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
+ g_log_err->writer().add_formatter( formatter::append_newline() );
+ g_log_err->writer().add_destination( destination::file("err.txt") );
+
+ destination::file out("out.txt");
+ // App log
+ g_log_app->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
+ g_log_app->writer().add_formatter( formatter::append_newline() );
+ g_log_app->writer().add_destination( out );
+ g_log_app->writer().add_destination( destination::cout() );
+
+ // Debug log
+ g_log_dbg->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
+ g_log_dbg->writer().add_formatter( formatter::append_newline() );
+ g_log_dbg->writer().add_destination( out );
+ g_log_dbg->writer().add_destination( destination::dbg_window() );
+
+ // if you change this, you'll get a different output (more or less verbose)
+ g_log_level->set_enabled(level::info);
+
+ g_log_err->turn_cache_off();
+ g_log_app->turn_cache_off();
+ g_log_dbg->turn_cache_off();
+}
+
+void cache_before_init_example() {
+ init_logs();
+ int i = 10;
+ LAPP_ << "after logs have been initialized " << i++;
+ g_log_level->set_enabled(level::debug);
+ LDBG_ << "some debug message after logs have been initialized " << i++;
+}
+
+
+
+
+int main() {
+ cache_before_init_example();
+}
+
+
+// End of file
+

Modified: sandbox/logging/lib/logging/samples/scenarios/custom_fmt_dest.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/custom_fmt_dest.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/custom_fmt_dest.cpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -122,6 +122,7 @@
     g_l->writer().add_destination( destination::cout() );
     g_l->writer().add_destination( destination::dbg_window() );
     g_l->writer().add_destination( as_xml("out.txt") );
+ g_l->turn_cache_off();
 
     // Step 8: use it...
     int i = 1;

Modified: sandbox/logging/lib/logging/samples/scenarios/ded_loger_one_filter.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/ded_loger_one_filter.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/ded_loger_one_filter.cpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -113,6 +113,7 @@
     g_l->writer().add_formatter( formatter::append_newline() );
     g_l->writer().add_destination( destination::file("out.txt") );
     g_l->writer().add_destination( destination::dbg_window() );
+ g_l->turn_cache_off();
 
     for ( int i = 0 ; i < 5; ++i)
         boost::thread t( &use_log_thread);

Modified: sandbox/logging/lib/logging/samples/scenarios/fastest_no_ostr_like.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/fastest_no_ostr_like.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/fastest_no_ostr_like.cpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -41,6 +41,7 @@
 using namespace boost::logging;
 
 struct no_gather {
+ typedef const char* msg_type ;
     const char * m_msg;
     no_gather() : m_msg(0) {}
     const char * msg() const { return m_msg; }
@@ -66,6 +67,9 @@
 #define LERR_ BOOST_LOG_USE_SIMPLE_LOG_IF_FILTER(g_log_err, g_log_filter->is_enabled() )
 
 void fastest_no_ostr_like_example() {
+ g_log_app->turn_cache_off();
+ g_log_err->turn_cache_off();
+
     // Step 5: use it...
     LAPP_("this is so cool\n");
     LERR_("first error \n");

Modified: sandbox/logging/lib/logging/samples/scenarios/fastest_use_ostr_like.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/fastest_use_ostr_like.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/fastest_use_ostr_like.cpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -58,6 +58,9 @@
 #define LERR_ BOOST_LOG_USE_LOG_IF_FILTER(g_log_err, g_log_filter->is_enabled() )
 
 void fastest_use_ostr_like_example() {
+ g_log_app->turn_cache_off();
+ g_log_err->turn_cache_off();
+
     // Step 5: use it...
     int i = 1;
     LAPP_ << "this is so cool " << i++ << "\n";

Modified: sandbox/logging/lib/logging/samples/scenarios/mul_levels_mul_logers.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/mul_levels_mul_logers.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/mul_levels_mul_logers.cpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -113,6 +113,10 @@
     g_log_dbg->writer().add_destination( out );
     g_log_dbg->writer().add_destination( destination::dbg_window() );
 
+ g_log_app->turn_cache_off();
+ g_log_err->turn_cache_off();
+ g_log_dbg->turn_cache_off();
+
     // Step 8: use it...
     int i = 1;
     LDBG_ << "this is so cool " << i++;

Modified: sandbox/logging/lib/logging/samples/scenarios/mul_levels_one_logger.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/mul_levels_one_logger.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/mul_levels_one_logger.cpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -66,6 +66,8 @@
             .add( "debug", destination::dbg_window() )
          );
 
+ g_l->turn_cache_off();
+
     // Step 8: use it...
     int i = 1;
     LDBG_ << "this is so cool " << i++;

Modified: sandbox/logging/lib/logging/samples/scenarios/mul_loggers_one_filter.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/mul_loggers_one_filter.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/mul_loggers_one_filter.cpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -109,6 +109,10 @@
     g_log_dbg->writer().add_destination( destination::dbg_window() );
     g_log_dbg->writer().add_destination( destination::cout() );
 
+ g_log_app->turn_cache_off();
+ g_log_err->turn_cache_off();
+ g_log_dbg->turn_cache_off();
+
     // Step 8: use it...
     int i = 1;
     LDBG_ << "this is so cool " << i++;

Modified: sandbox/logging/lib/logging/samples/scenarios/no_levels_with_route.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/no_levels_with_route.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/no_levels_with_route.cpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -107,6 +107,8 @@
         .fmt( formatter::append_newline() )
         .dest( destination::file("out.txt") );
 
+ g_l->turn_cache_off();
+
     // Step 8: use it...
     int i = 1;
     L_ << "this is so cool " << i++;

Modified: sandbox/logging/lib/logging/samples/scenarios/one_loger_one_filter.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/one_loger_one_filter.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/one_loger_one_filter.cpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -67,6 +67,8 @@
     g_l->writer().add_destination( destination::cout() );
     g_l->writer().add_destination( destination::dbg_window() );
 
+ g_l->turn_cache_off();
+
     // Step 8: use it...
     int i = 1;
     L_ << "this is so cool " << i++;

Modified: sandbox/logging/lib/logging/samples/scenarios/ts_loger_one_filter.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/ts_loger_one_filter.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/ts_loger_one_filter.cpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -106,6 +106,7 @@
     g_l->writer().add_destination( destination::file("out.txt") );
     g_l->writer().add_destination( destination::cout() );
     g_l->writer().add_destination( destination::dbg_window() );
+ g_l->turn_cache_off();
 
     for ( int i = 0 ; i < 5; ++i)
         boost::thread t( &use_log_thread);

Modified: sandbox/logging/lib/logging/samples/scenarios/use_tss_ostringstream.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/use_tss_ostringstream.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/use_tss_ostringstream.cpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -40,16 +40,6 @@
 
 BOOST_LOG_GATHER_CLASS( use_ostringstream< tss_ostringstream<> > )
 
-#if 0
- namespace boost { namespace logging { namespace gather {
- template<> struct find<override> {
- template<class msg_type> struct from_msg_type {
- typedef typename ::boost::logging::detail::find_gather_from_class<msg_type, use_ostringstream< tss_ostringstream<> > > ::type type;
- };
- };
- }}}
-#endif
-
 
 #include <boost/logging/format.hpp>
 #include <boost/logging/writer/ts_write.hpp>
@@ -80,6 +70,7 @@
     g_l->writer().add_formatter( formatter::append_newline_if_needed() );
     g_l->writer().add_destination( destination::cout() );
     g_l->writer().add_destination( destination::dbg_window() );
+ g_l->turn_cache_off();
 
     // Step 8: use it...
     int i = 1;

Modified: sandbox/logging/lib/logging/samples/scenarios/using_tags.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/using_tags.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/using_tags.cpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -80,6 +80,7 @@
     g_l->writer().add_formatter( formatter::append_newline() );
     g_l->writer().add_destination( destination::cout() );
     g_l->writer().add_destination( destination::file("out.txt") );
+ g_l->turn_cache_off();
 
     // Step 8: use it...
     int i = 1;

Modified: sandbox/logging/lib/logging/samples/scenarios/your_scenario.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/your_scenario.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/your_scenario.cpp 2008-01-04 10:52:56 EST (Fri, 04 Jan 2008)
@@ -135,6 +135,9 @@
     g_log_dbg->writer().add_formatter( formatter::append_newline() );
     g_log_dbg->writer().add_destination( destination::dbg_window() );
     g_log_dbg->writer().add_destination( destination::cout() );
+ g_log_app->turn_cache_off();
+ g_log_err->turn_cache_off();
+ g_log_dbg->turn_cache_off();
 
     // Step 8: use it...
     int i = 1;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk