Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2008-02-03 10:20:46


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

Log:
[logging]
v0.22.2, 3 feb 2008
- solved bug in no_levels_with_route - care about formatter::spacer

Properties modified:
   sandbox/logging/lib/logging/tests/test_on_ded_thread/ (props changed)
Text files modified:
   sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp | 3
   sandbox/logging/boost/logging/format.hpp | 11 ++
   sandbox/logging/lib/logging/internal/vc8/loggingvc8/test_now.cpp | 140 +++++++++++++++++++++++++++++----------
   3 files changed, 114 insertions(+), 40 deletions(-)

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:20:45 EST (Sun, 03 Feb 2008)
@@ -1,7 +1,8 @@
 /**
 @page page_changelog Changelog
 
-_at_section changelog_cur_ver Current Version: v0.22.1, 3 feb 2008
+@section changelog_cur_ver Current Version: v0.22.2, 3 feb 2008
+- 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/format.hpp
==============================================================================
--- sandbox/logging/boost/logging/format.hpp (original)
+++ sandbox/logging/boost/logging/format.hpp 2008-02-03 10:20:45 EST (Sun, 03 Feb 2008)
@@ -28,6 +28,7 @@
 #include <vector>
 #include <set>
 #include <boost/shared_ptr.hpp>
+#include <boost/assert.hpp>
 
 #include <boost/type_traits/is_base_of.hpp>
 #include <boost/logging/detail/manipulator.hpp>
@@ -402,8 +403,14 @@
             };
             struct item {
                 item() : m_fmt(0), m_dest(0), m_type(is_clear) {}
- item& fmt(formatter_ptr f) { m_fmt = f; m_type = is_fmt; return *this; }
- item &dest(destination_ptr d) { m_dest = d; m_type = is_dest; return *this; }
+ item& fmt(formatter_ptr f) {
+ BOOST_ASSERT(f);
+ m_fmt = f; m_type = is_fmt; return *this;
+ }
+ item &dest(destination_ptr d) {
+ BOOST_ASSERT(d);
+ m_dest = d; m_type = is_dest; return *this;
+ }
                 formatter_ptr m_fmt;
                 destination_ptr m_dest;
                 type m_type;

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:20:45 EST (Sun, 03 Feb 2008)
@@ -1,68 +1,134 @@
 /**
-_at_example mul_levels_one_logger.cpp
+@example no_levels_with_route.cpp
 
-_at_copydoc mul_levels_one_logger
+@copydoc no_levels_with_route
 
-_at_page mul_levels_one_logger mul_levels_one_logger.cpp Example
+@page no_levels_with_route no_levels_with_route.cpp Example
 
 This usage:
-- You have multiple levels (in this example: debug < info < error)
-- You want to format the message before it's written
- (in this example: prefix it by time, by index, and append newline to it)
-- You have <b>one log</b>, which writes to several log destinations
- (in this example: the console, the debug output window, and a file)
+- There are no levels
+- There is only one logger
+- The logger has multiple destinations
+- We use a custom route
 
-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:
+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:
 @code
-21:03.17.243 [1] this is so cool 1
-21:03.17.243 [2] first error 2
-21:03.17.243 [3] hello, world
-21:03.17.243 [4] second error 3
-21:03.17.243 [5] good to be back ;) 4
-21:03.17.243 [6] third error 5
+to cout: [idx] [time] message [enter]
+to dbg_window: [time] message [enter]
+to file: [idx] message [enter]
+@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).
+
+The output will be similar to this:
+
+The debug window
+@code
+12:15.12 this is so cool 1
+12:15.12 hello, world
+12:15.12 good to be back ;) 2
+@endcode
+
+The file:
+@code
+[1] this is so cool 1
+[2] hello, world
+[3] good to be back ;) 2
+@endcode
+
+The console:
+@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
 @endcode
 
 */
 
 
-#include <boost/logging/format/named_write.hpp>
-typedef boost::logging::named_logger<>::type logger_type;
 
-#define L_(lvl) BOOST_LOG_USE_LOG_IF_LEVEL(g_l(), g_log_level(), lvl )
+#include <boost/logging/format_fwd.hpp>
 
-BOOST_DEFINE_LOG_FILTER(g_log_level, boost::logging::level::holder ) // holds the application log level
+BOOST_LOG_FORMAT_MSG( optimize::cache_string_several_str<> )
+
+#include <boost/logging/format.hpp>
+
+using namespace boost::logging;
+
+
+typedef logger_format_write< > logger_type;
+
+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() )
+
+BOOST_DEFINE_LOG_FILTER(g_log_filter, filter::no_ts )
 BOOST_DEFINE_LOG(g_l, logger_type)
 
-void test_mul_levels_one_logger() {
- // formatting : time [idx] message \n
- // destinations : console, file "out.txt" and debug window
- g_l()->writer().write("%time%($hh:$mm.$ss.$mili) [%idx%] |\n", "cout file(out.txt) debug");
+void no_levels_with_route_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() );
+
+ // ... and where should it be written to
+ 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_(debug) << "this is so cool " << i++;
- L_(error) << "first error " << i++;
+ L_ << "this is so cool " << i++;
 
     std::string hello = "hello", world = "world";
- L_(debug) << hello << ", " << world;
+ L_ << hello << ", " << world;
 
- using namespace boost::logging;
- g_log_level()->set_enabled(level::error);
- L_(debug) << "this will not be written anywhere";
- L_(info) << "this won't be written anywhere either";
- L_(error) << "second error " << i++;
-
- g_log_level()->set_enabled(level::info);
- L_(info) << "good to be back ;) " << i++;
- L_(error) << "third error " << i++;
+ 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++;
 }
 
 
 
+
 int main() {
- test_mul_levels_one_logger();
+ no_levels_with_route_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