Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2008-02-03 10:53:40


Author: jtorjo
Date: 2008-02-03 10:53:38 EST (Sun, 03 Feb 2008)
New Revision: 43072
URL: http://svn.boost.org/trac/boost/changeset/43072

Log:
[logging]
v0.22.3, 3 feb 2008
- solved bug in using_tags - delete_array used after logger destroyed
Text files modified:
   sandbox/logging/boost/logging/detail/logger_base.hpp | 10 ++
   sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp | 3
   sandbox/logging/boost/logging/detail/tss/tss_ensure_proper_delete.hpp | 1
   sandbox/logging/lib/logging/internal/vc8/loggingvc8/test_now.cpp | 141 +++++++++++++--------------------------
   4 files changed, 61 insertions(+), 94 deletions(-)

Modified: sandbox/logging/boost/logging/detail/logger_base.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/logger_base.hpp (original)
+++ sandbox/logging/boost/logging/detail/logger_base.hpp 2008-02-03 10:53:38 EST (Sun, 03 Feb 2008)
@@ -22,6 +22,8 @@
 #endif
 
 #include <boost/logging/detail/fwd.hpp>
+#include <boost/logging/detail/tss/tss.hpp>
+
 // see "Using the logger(s)/filter(s) after they've been destroyed" section in the documentation
 //#include <boost/logging/detail/after_being_destroyed.hpp>
 
@@ -130,7 +132,13 @@
         typedef detail::common_base_holder<gather_msg, write_msg> common_base_type;
 
     protected:
- logger_base() {}
+ logger_base() {
+#if defined(BOOST_LOG_TSS_USE_INTERNAL)
+ // we need ALL loggers to depend on delete_array - this way, delete_array will be destroyed
+ // after all loggers are destroyed
+ detail::new_object_ensure_delete< default_ > ();
+#endif
+ }
         logger_base(const logger_base&) {}
 
     private:

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-02-03 10:53:38 EST (Sun, 03 Feb 2008)
@@ -1,7 +1,8 @@
 /**
 @page page_changelog Changelog
 
-_at_section changelog_cur_ver Current Version: v0.22.2, 3 feb 2008
+@section changelog_cur_ver Current Version: v0.22.3, 3 feb 2008
+- solved bug in using_tags - delete_array used after logger destroyed
 - solved bug in no_levels_with_route - care about formatter::spacer
 - solved gcc warning - m_writer initialized before m_original_logger
 - fixed issue in Jamfile.v2 - runtime-link should refer only to msvc

Modified: sandbox/logging/boost/logging/detail/tss/tss_ensure_proper_delete.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/tss/tss_ensure_proper_delete.hpp (original)
+++ sandbox/logging/boost/logging/detail/tss/tss_ensure_proper_delete.hpp 2008-02-03 10:53:38 EST (Sun, 03 Feb 2008)
@@ -46,6 +46,7 @@
     typedef boost::logging::threading::mutex mutex;
     typedef std::vector< do_delete_base* > vector_base;
 
+ delete_array() {}
     ~delete_array () {
         for ( const_iterator b = begin(), e = end(); b != e; ++b)
             delete *b;

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-02-03 10:53:38 EST (Sun, 03 Feb 2008)
@@ -1,50 +1,27 @@
 /**
-_at_example no_levels_with_route.cpp
+@example using_tags.cpp
 
-_at_copydoc no_levels_with_route
+@copydoc using_tags
 
-_at_page no_levels_with_route no_levels_with_route.cpp Example
+@page using_tags using_tags.cpp Example
 
-This usage:
-- There are no levels
-- There is only one logger
-- The logger has multiple destinations
-- We use a custom route
-
-A custom route means you don't want to first run all formatters, and then write to all destinations.
-Depending on the destination, you'll want a certain formatting of the message
-
-In our example:
-_at_code
-to cout: [idx] [time] message [enter]
-to dbg_window: [time] message [enter]
-to file: [idx] message [enter]
-_at_endcode
 
-We will use an @c apply_format_and_write class that caches the formatting, so that it'll format faster
-(more specifically, the boost::logging::format_and_write::use_cache, together with boost::logging::optimize::cache_string_several_str).
+This usage:
+- You have one logger and one filter, which can be turned on or off
+- You want to format the message before it's written
+- The logger has several log destinations
+ - The output goes to console, and a file called out.txt
+ - Formatting - message will look like this: <tt>[file/line] [thread_id] [idx] [time] message [enter] </tt>
 
-The output will be similar to this:
+Optimizations:
+- use a cache string (from optimize namespace), in order to make formatting the message faster
 
-The debug window
-_at_code
-12:15.12 this is so cool 1
-12:15.12 hello, world
-12:15.12 good to be back ;) 2
-_at_endcode
+In this example, all output will be written to the console, debug window, and "out.txt" file.
+The output can look like:
 
-The file:
 @code
-[1] this is so cool 1
-[2] hello, world
-[3] good to be back ;) 2
-_at_endcode
-
-The console:
-_at_code
-[1] 12:15.12 this is so cool 1
-[2] 12:15.12 hello, world
-[3] 12:15.12 good to be back ;) 2
+logging\samples\scenarios\using_tags.cpp:94 [T7204] [1] 14:55 this is so cool 1
+logging\samples\scenarios\using_tags.cpp:95 [T7204] [2] 14:55 this is so cool again 2
 @endcode
 
 */
@@ -53,82 +30,62 @@
 
 #include <boost/logging/format_fwd.hpp>
 
-BOOST_LOG_FORMAT_MSG( optimize::cache_string_several_str<> )
+namespace bl = boost::logging;
+typedef bl::tag::holder< bl::optimize::cache_string_one_str<>, bl::tag::file_line, bl::tag::thread_id, bl::tag::time> log_string;
+BOOST_LOG_FORMAT_MSG( log_string )
 
-#include <boost/logging/format.hpp>
 
-using namespace boost::logging;
+#include <boost/logging/format_ts.hpp>
+#include <boost/logging/format/formatter/tags.hpp>
+#include <boost/logging/format/formatter/named_spacer.hpp>
 
+using namespace boost::logging;
 
-typedef logger_format_write< > logger_type;
+using namespace boost::logging::scenario::usage;
+typedef use<
+ // the filter is always accurate (but slow)
+ filter_::change::always_accurate,
+ // filter does not use levels
+ filter_::level::no_levels,
+ // the logger is initialized once, when only one thread is running
+ logger_::change::set_once_when_one_thread,
+ // the logger favors speed (on a dedicated thread)
+ logger_::favor::speed> finder;
+
+BOOST_DECLARE_LOG_FILTER(g_log_filter, finder::filter )
+BOOST_DECLARE_LOG(g_l, finder::logger)
 
-BOOST_DECLARE_LOG_FILTER(g_log_filter, filter::no_ts )
-BOOST_DECLARE_LOG(g_l, logger_type)
+#define L_ BOOST_LOG_USE_LOG_IF_FILTER(g_l(), g_log_filter()->is_enabled() ) .set_tag( BOOST_LOG_TAG_FILELINE)
 
-#define L_ BOOST_LOG_USE_LOG_IF_FILTER(g_l(), g_log_filter()->is_enabled() )
+BOOST_DEFINE_LOG_FILTER(g_log_filter, finder::filter )
+BOOST_DEFINE_LOG(g_l, finder::logger)
 
-BOOST_DEFINE_LOG_FILTER(g_log_filter, filter::no_ts )
-BOOST_DEFINE_LOG(g_l, logger_type)
 
-void no_levels_with_route_example() {
+void using_tags_example() {
     // add formatters and destinations
- // That is, how the message is to be formatted...
- g_l()->writer().add_formatter( formatter::idx(), "[%] " );
- g_l()->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
- g_l()->writer().add_formatter( formatter::append_newline() );
+ // That is, how the message is to be formatted and where should it be written to
 
- // ... and where should it be written to
+ g_l()->writer().add_formatter( formatter::named_spacer( "%fileline% [T%thread_id%] [%idx%] %time%" )
+ .add( "time", formatter::tag::time("$mm:$ss ") ) // time tag
+ .add( "idx", formatter::idx() )
+ .add( "thread_id", formatter::tag::thread_id() ) // thread_id tag
+ .add( "fileline", formatter::tag::file_line() ) ); // file/line tag
+
+ g_l()->writer().add_formatter( formatter::append_newline() );
     g_l()->writer().add_destination( destination::cout() );
- g_l()->writer().add_destination( destination::dbg_window() );
     g_l()->writer().add_destination( destination::file("out.txt") );
-
- // Now, specify the route
- g_l()->writer().router().set_route()
- .fmt( formatter::time("$hh:$mm.$ss ") )
- .fmt( formatter::append_newline() )
- /*
- Not like this: .fmt( formatter::idx() )
-
- This is because
- add_formatter( formatter::idx(), "[%] " );
- has surrounded formatter::idx() in a spacer - see formatter::spacer
- */
- .fmt( formatter::spacer( formatter::idx(), "[%] ") )
- .clear()
- .fmt( formatter::time("$hh:$mm.$ss ") )
- .fmt( formatter::append_newline() )
- .dest( destination::dbg_window() )
- .clear()
- .fmt( formatter::spacer( formatter::idx(), "[%] ") )
- .fmt( formatter::time("$hh:$mm.$ss ") )
- .fmt( formatter::append_newline() )
- .dest( destination::cout() )
- .clear()
- .fmt( formatter::spacer( formatter::idx(), "[%] ") )
- .fmt( formatter::append_newline() )
- .dest( destination::file("out.txt") );
-
     g_l()->mark_as_initialized();
 
     int i = 1;
     L_ << "this is so cool " << i++;
-
- std::string hello = "hello", world = "world";
- L_ << hello << ", " << world;
-
- g_log_filter()->set_enabled(false);
- L_ << "this will not be written anywhere";
- L_ << "this won't be written anywhere either";
-
- g_log_filter()->set_enabled(true);
- L_ << "good to be back ;) " << i++;
+ L_ << "this is so cool again " << i++;
 }
 
 
 
 
 int main() {
- no_levels_with_route_example();
+ using_tags_example();
 }
 
 


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