|
Boost-Commit : |
From: john.groups_at_[hidden]
Date: 2008-02-03 11:05:49
Author: jtorjo
Date: 2008-02-03 11:05:48 EST (Sun, 03 Feb 2008)
New Revision: 43073
URL: http://svn.boost.org/trac/boost/changeset/43073
Log:
[logging]
now i fixed the no_levels_with_route.cpp bug (prev time i copied the fix into test_now.cpp)
Text files modified:
sandbox/logging/lib/logging/internal/vc8/loggingvc8/test_now.cpp | 134 +++++++++++++++++++++++++--------------
sandbox/logging/lib/logging/samples/scenarios/ded_loger_one_filter.cpp | 1
sandbox/logging/lib/logging/samples/scenarios/no_levels_with_route.cpp | 13 ++
3 files changed, 96 insertions(+), 52 deletions(-)
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 11:05:48 EST (Sun, 03 Feb 2008)
@@ -1,27 +1,50 @@
/**
-_at_example using_tags.cpp
+@example no_levels_with_route.cpp
-_at_copydoc using_tags
-
-_at_page using_tags using_tags.cpp Example
+@copydoc no_levels_with_route
+@page no_levels_with_route no_levels_with_route.cpp Example
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>
+- 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:
+@code
+to cout: [idx] [time] message [enter]
+to dbg_window: [time] message [enter]
+to file: [idx] message [enter]
+@endcode
-Optimizations:
-- use a cache string (from optimize namespace), in order to make formatting the message faster
+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).
-In this example, all output will be written to the console, debug window, and "out.txt" file.
-The output can look like:
+The output will be similar to this:
+The debug window
@code
-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
+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
*/
@@ -30,62 +53,75 @@
#include <boost/logging/format_fwd.hpp>
-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 )
-
+BOOST_LOG_FORMAT_MSG( optimize::cache_string_several_str<> )
-#include <boost/logging/format_ts.hpp>
-#include <boost/logging/format/formatter/tags.hpp>
-#include <boost/logging/format/formatter/named_spacer.hpp>
+#include <boost/logging/format.hpp>
using namespace boost::logging;
-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)
-#define L_ BOOST_LOG_USE_LOG_IF_FILTER(g_l(), g_log_filter()->is_enabled() ) .set_tag( BOOST_LOG_TAG_FILELINE)
+typedef logger_format_write< > logger_type;
-BOOST_DEFINE_LOG_FILTER(g_log_filter, finder::filter )
-BOOST_DEFINE_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() )
-void using_tags_example() {
- // add formatters and destinations
- // That is, how the message is to be formatted and where should it be written to
+BOOST_DEFINE_LOG_FILTER(g_log_filter, filter::no_ts )
+BOOST_DEFINE_LOG(g_l, logger_type)
- 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
+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() );
- 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() )
+ .fmt( formatter::idx() )
+ .clear()
+ .fmt( formatter::time("$hh:$mm.$ss ") )
+ .fmt( formatter::append_newline() )
+ .dest( destination::dbg_window() )
+ .clear()
+ .fmt( formatter::idx() )
+ .fmt( formatter::time("$hh:$mm.$ss ") )
+ .fmt( formatter::append_newline() )
+ .dest( destination::cout() )
+ .clear()
+ .fmt( 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++;
- L_ << "this is so cool again " << 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++;
}
int main() {
- using_tags_example();
+ no_levels_with_route_example();
}
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-02-03 11:05:48 EST (Sun, 03 Feb 2008)
@@ -106,6 +106,7 @@
boost::thread t( &use_log_thread);
// allow for all threads to finish
+ std::cout << "sleep 5s " << std::endl;
do_sleep( 5000);
}
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-02-03 11:05:48 EST (Sun, 03 Feb 2008)
@@ -86,18 +86,25 @@
g_l()->writer().router().set_route()
.fmt( formatter::time("$hh:$mm.$ss ") )
.fmt( formatter::append_newline() )
- .fmt( formatter::idx() )
+ /*
+ 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::idx() )
+ .fmt( formatter::spacer( formatter::idx(), "[%] ") )
.fmt( formatter::time("$hh:$mm.$ss ") )
.fmt( formatter::append_newline() )
.dest( destination::cout() )
.clear()
- .fmt( formatter::idx() )
+ .fmt( formatter::spacer( formatter::idx(), "[%] ") )
.fmt( formatter::append_newline() )
.dest( destination::file("out.txt") );
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