Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2007-10-22 05:37:33


Author: jtorjo
Date: 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
New Revision: 40279
URL: http://svn.boost.org/trac/boost/changeset/40279

Log:
[logging]
v0.8.2, 22 oct 2007
- added one more common scenario (with_route)

Added:
   sandbox/logging/lib/logging/samples/scenarios/no_levels_with_route.cpp (contents, props changed)
Properties modified:
   sandbox/logging/lib/logging/samples/vc8/loggingvc8/ (props changed)
Text files modified:
   sandbox/logging/boost/logging/detail/raw_doc/Doxyfile_web.txt | 5 +-
   sandbox/logging/boost/logging/detail/raw_doc/acknowledgments.hpp | 1
   sandbox/logging/boost/logging/detail/raw_doc/fixme.hpp | 3 -
   sandbox/logging/boost/logging/detail/raw_doc/scenarios.hpp | 9 ++++
   sandbox/logging/boost/logging/detail/raw_doc/scenarios_code.hpp | 14 +++++++-
   sandbox/logging/boost/logging/detail/raw_doc/table_of_contents.hpp | 1
   sandbox/logging/boost/logging/detail/use_format_write.hpp | 25 ++++++++++++++
   sandbox/logging/boost/logging/format.hpp | 54 +++++++++++++++++++++++++-------
   sandbox/logging/boost/logging/format/formatter/convert_format.hpp | 21 ++++++++++++
   sandbox/logging/boost/logging/format/op_equal.hpp | 2
   sandbox/logging/boost/logging/format/optimize.hpp | 67 +++++++++++++++++++++++++++++++--------
   sandbox/logging/boost/logging/macros.hpp | 3 +
   sandbox/logging/boost/logging/process_msg/ostream_like.hpp | 4 +
   sandbox/logging/lib/logging/samples/scenarios/mul_levels_mul_logers.cpp | 2
   sandbox/logging/lib/logging/samples/vc8/loggingvc8/loggingvc8.vcproj | 19 +++++++++++
   sandbox/logging/lib/logging/src/changelog.txt | 3 +
   16 files changed, 196 insertions(+), 37 deletions(-)

Modified: sandbox/logging/boost/logging/detail/raw_doc/Doxyfile_web.txt
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/Doxyfile_web.txt (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/Doxyfile_web.txt 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -85,7 +85,8 @@
 #---------------------------------------------------------------------------
 # configuration options related to the input files
 #---------------------------------------------------------------------------
-INPUT = ../..
+INPUT = ../.. \
+ ../../../../lib/logging/samples/scenarios
 INPUT_ENCODING = UTF-8
 FILE_PATTERNS = *.c \
                          *.cc \
@@ -119,7 +120,7 @@
 EXCLUDE_SYMLINKS = NO
 EXCLUDE_PATTERNS =
 EXCLUDE_SYMBOLS =
-EXAMPLE_PATH =
+EXAMPLE_PATH = ../../../../lib/logging/samples/scenarios
 EXAMPLE_PATTERNS = *
 EXAMPLE_RECURSIVE = NO
 IMAGE_PATH =

Modified: sandbox/logging/boost/logging/detail/raw_doc/acknowledgments.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/acknowledgments.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/acknowledgments.hpp 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -11,6 +11,7 @@
 - Caleb Epstein - for porting parts of my code to any non-Windows OS, and implementing several formatters and destinations
 - Stefan Slapeta and Bill Wade and a lot of others for giving me early feedback.
 - Pavel Vozelinek - for very thourough reviews and lots of comments
+- Pavel Savara - for feedback about docs, thread-safety and gcc
 
 */
 

Modified: sandbox/logging/boost/logging/detail/raw_doc/fixme.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/fixme.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/fixme.hpp 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -8,8 +8,7 @@
 
 
 scenarios:
-have 3 scenarios
-- with custom router FIXME (that is, use cache_string_several_str())
+remaining scenarios
 - one logger; several levels - use a sink (that is, see how we find "is_enabled")
   - we can simply use the level.is_enabled(xxx) question, and then write to the log
 - no levels

Modified: sandbox/logging/boost/logging/detail/raw_doc/scenarios.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/scenarios.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/scenarios.hpp 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -5,10 +5,11 @@
 
 - @ref common_scenarios_1
 - @ref common_scenarios_2
+- @ref common_scenarios_3
 
 @copydoc common_usage_steps_fd
 
-_at_section common_scenarios_1 Common usage: Multiple levels, One logging class, Multiple destinations.
+@section common_scenarios_1 Scenario 1, Common usage: Multiple levels, One logging class, Multiple destinations.
 
 Scenario 1 should be the most common.
 
@@ -25,6 +26,12 @@
 \n\n\n
 
 
+@section common_scenarios_3 Scenario 3: No levels, One Logger, Multiple destinations, Custom route
+
+@copydoc no_levels_with_route
+
+@ref scenarios_code_3 "Click to see the code"
+
 */
 
 }}

Modified: sandbox/logging/boost/logging/detail/raw_doc/scenarios_code.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/scenarios_code.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/scenarios_code.hpp 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -5,20 +5,30 @@
 
 - @ref scenarios_code_1
 - @ref scenarios_code_2
+- @ref scenarios_code_3
 
 
-
-_at_section scenarios_code_1 Common usage: Multiple levels, One logging class, Multiple destinations.
+\n\n\n
+@section scenarios_code_1 Scenario 1, Common usage: Multiple levels, One logging class, Multiple destinations.
 
 @include mul_levels_one_logger.cpp
 \n\n\n
 
+
+
 @section scenarios_code_2 Scenario 2: Multiple levels, Multiple logging classes, Multiple destinations
 
 @include mul_levels_mul_logers.cpp
 \n\n\n
 
 
+
+@section scenarios_code_3 Scenario 3: No levels, One Logger, Multiple destinations, Custom route
+
+@include no_levels_with_route.cpp
+\n\n\n
+
+
 */
 
 }}

Modified: sandbox/logging/boost/logging/detail/raw_doc/table_of_contents.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/table_of_contents.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/table_of_contents.hpp 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -9,6 +9,7 @@
 - @ref common_scenarios
     - @ref common_scenarios_1
     - @ref common_scenarios_2
+ - @ref common_scenarios_3
 
 - @ref workflow
     - @ref workflow_introduction

Modified: sandbox/logging/boost/logging/detail/use_format_write.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/use_format_write.hpp (original)
+++ sandbox/logging/boost/logging/detail/use_format_write.hpp 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -44,6 +44,19 @@
         struct find_gather< boost::logging::optimize::cache_string_several_str<string_type> > {
             typedef gather::ostream_like::return_cache_str< boost::logging::optimize::cache_string_several_str<string_type> > type;
         };
+
+ template<class string, class formatter_base, class destination_base> struct find_format_write_params {
+ typedef typename boost::logging::format_and_write::simple<string> apply_format_and_write ;
+ typedef typename msg_route::simple<formatter_base, destination_base> router_type;
+ };
+
+ template<class string_type, class formatter_base, class destination_base>
+ struct find_format_write_params< typename boost::logging::optimize::cache_string_several_str<string_type>, formatter_base, destination_base>
+ {
+ typedef typename boost::logging::optimize::cache_string_several_str<string_type> cache_string;
+ typedef typename boost::logging::format_and_write::use_cache<formatter_base, destination_base, cache_string> apply_format_and_write ;
+ typedef typename msg_route::with_route<formatter_base, destination_base> router_type;
+ };
     }
 
 /**
@@ -71,13 +84,23 @@
 template<class format_base, class destination_base> struct use_format_write {
     typedef typename format_base::raw_param format_param;
     typedef typename detail::find_gather<format_param>::type gather_type;
+
+ typedef typename detail::find_format_write_params<format_param, format_base, destination_base>::apply_format_and_write apply_format_and_write;
+ typedef typename detail::find_format_write_params<format_param, format_base, destination_base>::router_type router_type;
 };
 
 template<class format_base, class destination_base> struct logger< use_format_write<format_base, destination_base> >
     : logger_base<
         process_msg<
             typename use_format_write<format_base, destination_base>::gather_type,
- writer::format_write<format_base,destination_base> > >
+ writer::format_write<
+ format_base,
+ destination_base,
+ typename use_format_write<format_base, destination_base>::apply_format_and_write,
+ typename use_format_write<format_base, destination_base>::router_type
+ >
+ >
+ >
 {
     typedef typename logger_base<
         process_msg<

Modified: sandbox/logging/boost/logging/format.hpp
==============================================================================
--- sandbox/logging/boost/logging/format.hpp (original)
+++ sandbox/logging/boost/logging/format.hpp 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -25,10 +25,13 @@
 #include <boost/logging/format/op_equal.hpp>
 #include <boost/logging/format/array.hpp>
 #include <vector>
+#include <set>
 #include <boost/shared_ptr.hpp>
 
 #include <boost/type_traits/remove_reference.hpp>
 #include <boost/type_traits/remove_const.hpp>
+#include <boost/type_traits/is_base_of.hpp>
+#include <boost/logging/detail/manipulator.hpp>
 
 namespace boost { namespace logging {
 
@@ -51,27 +54,34 @@
     /**
         @brief This uses a cache, when calling formatters/destinations - for writing a given message
 
- If a message was formatted before, it caches this info.
-
- FIXME this is not implemented yet
+ When a formatter is called, it caches its info. If it's called again, reuses that.
     */
     template<class formatter_base, class destination_base, class msg_type>
     struct use_cache {
         use_cache( msg_type & msg) : m_msg(msg) {}
 
-#if 0
- void format(const formatter_ptr & fmt) {
- // FIXME
+ typedef typename formatter_base::ptr_type formatter_ptr;
+ typedef typename destination_base::ptr_type destination_ptr;
+ typedef std::set<formatter_ptr> format_set;
+
+ void format(formatter_ptr const &fmt) {
+ if ( m_formats.find( fmt) == m_formats.end()) {
+ m_formats.insert( fmt);
+ (*fmt)(m_msg);
+ m_msg.set_last_id( fmt);
+ }
+ else
+ m_msg.reuse( fmt);
         }
- void write(const destination_ptr & dest) {
- // FIXME
+ void write(destination_ptr const & dest) {
+ (*dest)(m_msg);
         }
         void clear_format() {
- // FIXME
+ m_msg.restart();
         }
-#endif
     private:
         msg_type &m_msg;
+ format_set m_formats;
     };
 
 
@@ -383,11 +393,11 @@
         public:
 
             template<class formatter> route & fmt(formatter f) {
- m_items.push_back( item().fmt( m_self.formats().get_ptr(f) )) ;
+ fmt_impl(f, boost::is_base_of<boost::logging::manipulator::is_generic,formatter>() );
                 return *this;
             }
             template<class destination> route & dest(destination d) {
- m_items.push_back( item().dest( m_self.destinations().get_ptr(d) ));
+ dest_impl(d, boost::is_base_of<boost::logging::manipulator::is_generic,destination>() );
                 return *this;
             }
             route & clear() {
@@ -395,6 +405,26 @@
                 return *this;
             }
 
+ private:
+ // not generic
+ template<class formatter> void fmt_impl(formatter f, const boost::false_type& ) {
+ m_items.push_back( item().fmt( m_self.formats().get_ptr(f) )) ;
+ }
+ // not generic
+ template<class destination> void dest_impl(destination d, const boost::false_type&) {
+ m_items.push_back( item().dest( m_self.destinations().get_ptr(d) ));
+ }
+
+ // generic
+ template<class formatter> void fmt_impl(formatter f, const boost::true_type& ) {
+ typedef boost::logging::manipulator::detail::generic_holder<formatter,formatter_base> holder;
+ fmt_impl( holder(f) , boost::false_type() );
+ }
+ // generic
+ template<class destination> void dest_impl(destination d, const boost::true_type&) {
+ typedef boost::logging::manipulator::detail::generic_holder<destination,destination_base> holder;
+ dest_impl( holder(d) , boost::false_type() );
+ }
         protected:
             self_type & m_self;
             array m_items;

Modified: sandbox/logging/boost/logging/format/formatter/convert_format.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/formatter/convert_format.hpp (original)
+++ sandbox/logging/boost/logging/format/formatter/convert_format.hpp 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -61,6 +61,9 @@
         template<class string> void write(const string_type & src, boost::logging::optimize::cache_string_one_str<string> & dest) {
             dest.prepend_string(src);
         }
+ template<class string> void write(const string_type & src, boost::logging::optimize::cache_string_several_str<string> & dest) {
+ dest.prepend_string(src);
+ }
     }
 
     /**
@@ -75,6 +78,9 @@
         template<class string> void write(const string_type & src, boost::logging::optimize::cache_string_one_str<string> & dest) {
             dest.append_string(src);
         }
+ template<class string> void write(const string_type & src, boost::logging::optimize::cache_string_several_str<string> & dest) {
+ dest.append_string(src);
+ }
     }
 
     /**
@@ -89,6 +95,12 @@
         template<class string> void write(const string_type & src, boost::logging::optimize::cache_string_one_str<string> & dest) {
             dest.set_string(src);
         }
+ template<class string> void write(const string_type & src, boost::logging::optimize::cache_string_several_str<string> & dest) {
+ dest.set_string(src);
+ }
+ template<class string> void write(string_type & src, boost::logging::optimize::cache_string_one_str<string> & dest) {
+ dest.set_string_swap(src);
+ }
     }
 }
 
@@ -101,18 +113,27 @@
         template<class src_type, class string> static void write(const src_type & src, string & dest) {
             convert::prepend::write(src, dest);
         }
+ template<class src_type, class string> static void write(src_type & src, string & dest) {
+ convert::prepend::write(src, dest);
+ }
     };
 
     struct append {
         template<class src_type, class string> static void write(const src_type & src, string & dest) {
             convert::append::write(src, dest);
         }
+ template<class src_type, class string> static void write(src_type & src, string & dest) {
+ convert::append::write(src, dest);
+ }
     };
 
     struct modify {
         template<class src_type, class string> static void write(const src_type & src, string & dest) {
             convert::modify::write(src, dest);
         }
+ template<class src_type, class string> static void write(src_type & src, string & dest) {
+ convert::modify::write(src, dest);
+ }
     };
 };
 

Modified: sandbox/logging/boost/logging/format/op_equal.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/op_equal.hpp (original)
+++ sandbox/logging/boost/logging/format/op_equal.hpp 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -62,7 +62,7 @@
         virtual bool equals(const same_type_op_equal_top & other) const {
             if ( typeid(*this) != typeid(other))
                 return false;
- const type & real_other = reinterpret_cast<const type&>(other);
+ const type & real_other = dynamic_cast<const type&>(other);
 
             // this forces 'type' to implement operator==
             return ((const type&)*this).operator ==( real_other);

Modified: sandbox/logging/boost/logging/format/optimize.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/optimize.hpp (original)
+++ sandbox/logging/boost/logging/format/optimize.hpp 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -64,7 +64,7 @@
         @param grow_size - in case we add a string and there's no room for it, with how much should we grow? We'll
                            grow this much in addition to the added string - in the needed direction
          */
- cache_string_one_str(const string_type & msg, int reserve_prepend, int reserve_append, int grow_size = 10)
+ cache_string_one_str(const string_type & msg, int reserve_prepend = 10, int reserve_append = 10, int grow_size = 10)
                 : m_reserve_prepend(reserve_prepend), m_reserve_append(reserve_append), m_grow_size(grow_size), m_full_msg_computed(false) {
             set_string(msg);
         }
@@ -188,11 +188,18 @@
         mutable string_type m_full_msg;
     };
 
+
+
+
+
     /**
         @brief This holds 3 strings - one for prepend, one for modification, and one for appending
 
         When you prepend or append, you can also specify an extra argument - an identifier.
         This identifier uniquely identifies the prepended or appended message.
+
+ Afterwards, you can prepend/append only by specifying an identifier - which will identify a previously
+ appended or prepended message
     */
     template<class string_type_ = boost::logging::hold_string_type, class ptr_type = void* > struct cache_string_several_str {
     private:
@@ -200,8 +207,8 @@
         typedef boost::shared_ptr<string_type> string_ptr;
 
         struct cached_msg {
- cached_msg() : prepended(true), id( ptr_type() ) {}
- cached_msg(const string_type & str, bool prepended) : msg(new string_type(str)), prepended(prepended) {}
+ cached_msg() : prepended(true), id( ptr_type() ), is_new(true) {}
+ cached_msg(const string_type & str, bool prepended) : msg(new string_type(str)), prepended(prepended), id( ptr_type() ), is_new(true) {}
 
             // when within the collection - it can never be null
             // when within the array - if null, use it from the collection
@@ -210,6 +217,8 @@
             bool prepended;
             // who wrote the message?
             ptr_type id;
+ // easily identify a message if it's new or it's been written before
+ bool is_new;
         };
 
     public:
@@ -224,6 +233,15 @@
         }
 
         /**
+ constructs an object
+
+ @param reserve_ [optional, default = 512] When creating the full msg, how much should we reserve?
+ */
+ cache_string_several_str(const string_type& msg, int reserve_ = 512) : m_msg(msg), m_full_msg_computed(false) {
+ m_full_msg.reserve(reserve_);
+ }
+
+ /**
             sets the string with a swap (that is, you pass a non-const refererence, and we do a swap)
         */
         void set_string_swap(string_type & msg) {
@@ -242,28 +260,36 @@
         /**
             @brief pre-pends a string (inserts it at the beginning)
         */
- void prepend_string(const string_type & str, ptr_type id = ptr_type() ) {
+ void prepend_string(const string_type & str ) {
+ m_cur_msg.push_back( cached_msg(str, true) );
             m_full_msg_computed = false;
         }
 
         /**
- @brief pre-pends a string (inserts it at the beginning). The message was already cached
+ @brief appends a string (inserts it at the end)
         */
- void prepend_string(ptr_type id ) {
+ void append_string(const string_type & str ) {
+ m_cur_msg.push_back( cached_msg(str, false) );
             m_full_msg_computed = false;
         }
 
         /**
- @brief appends a string (inserts it at the end)
+ Specifies the id of the last message
         */
- void append_string(const string_type & str, ptr_type id = ptr_type() ) {
- m_full_msg_computed = false;
+ void set_last_id(ptr_type id) {
+ m_cur_msg.back().id = id;
         }
 
         /**
- @brief appends a string (inserts it at the end). The message was already cached
+ @brief Reuses a pre-pended or appended string. The message was already cached
         */
- void append_string(ptr_type id ) {
+ void reuse(ptr_type id ) {
+ // make sure you first call restart() before reusing a formatter.
+ // In your code - this means calling set_route(). .... .clear(), and the writing to destinations
+ BOOST_ASSERT( m_cached.find(id) != m_cached.end() );
+
+ m_cur_msg.push_back( m_cached[id] );
+ m_cur_msg.back().is_new = false;
             m_full_msg_computed = false;
         }
 
@@ -273,7 +299,17 @@
         const string_type & full_string() const {
             if ( !m_full_msg_computed) {
                 m_full_msg_computed = true;
- // FIXME
+
+ m_full_msg.erase();
+ for ( array::const_iterator b = m_cur_msg.begin(), e = m_cur_msg.end(); b != e; ++b)
+ if ( b->prepended)
+ m_full_msg += *(b->msg);
+
+ m_full_msg += m_msg;
+
+ for ( array::const_iterator b = m_cur_msg.begin(), e = m_cur_msg.end(); b != e; ++b)
+ if ( !b->prepended)
+ m_full_msg += *(b->msg);
             }
             return m_full_msg;
         }
@@ -288,9 +324,12 @@
             @brief This restarts writing the messages. Whatever is cached can be used again
         */
         void restart() {
- // ******** whatever msg is in vector that has an id, it to be placed in coll.
- // FIXME also, need to work on the use_cache<> class from format_and_write
             m_full_msg_computed = false;
+
+ for ( array::const_iterator b = m_cur_msg.begin(), e = m_cur_msg.end(); b != e; ++b)
+ if ( b->is_new)
+ m_cached[ b->id ] = *b;
+ m_cur_msg.clear();
         }
 
     private:

Modified: sandbox/logging/boost/logging/macros.hpp
==============================================================================
--- sandbox/logging/boost/logging/macros.hpp (original)
+++ sandbox/logging/boost/logging/macros.hpp 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -120,6 +120,9 @@
 
 #define BOOST_LOG_USE_LOG_IF_LEVEL(l, holder, the_level) BOOST_LOG_USE_LOG(l, read_msg().gather().out(), holder.is_enabled(::boost::logging::level:: the_level) )
 
+#define BOOST_LOG_USE_LOG_IF_FILTER(l, the_filter) BOOST_LOG_USE_LOG(l, read_msg().gather().out(), the_filter)
+
+
 
 
 

Modified: sandbox/logging/boost/logging/process_msg/ostream_like.hpp
==============================================================================
--- sandbox/logging/boost/logging/process_msg/ostream_like.hpp (original)
+++ sandbox/logging/boost/logging/process_msg/ostream_like.hpp 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -179,6 +179,8 @@
     @sa ostream_like
 
     returns a cache string
+
+ @bug right now prepend_size and append_size are ignored; because we can also return a cache_string_several_str<>
 */
 template<
         class cache_string = boost::logging::optimize::cache_string_one_str<hold_string_type> ,
@@ -190,7 +192,7 @@
     return_cache_str(const return_cache_str& other) : m_out(other.m_out.str()) {}
 
     stream_type & out() { return m_out; }
- cache_string msg() { return cache_string( m_out.str(), prepend_size, append_size ); }
+ cache_string msg() { return cache_string( m_out.str() ); }
 private:
     stream_type m_out;
 };

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 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -90,7 +90,7 @@
 typedef formatter::base< cache_string& > formatter_base;
 typedef destination::base< const std::string & > destination_base;
 
-// Step 2 : define your logging class(es)
+// Step 2 : Define your logging class(es)
 typedef logger< use_format_write<formatter_base,destination_base> > log_type;
 
 // Step 3 : If you use levels, Set up a log level holder

Added: sandbox/logging/lib/logging/samples/scenarios/no_levels_with_route.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/samples/scenarios/no_levels_with_route.cpp 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -0,0 +1,158 @@
+// test_mul_levels_one_logger.hpp
+//
+// A test of the Logging library with multiple levels and one logging class writing to multiple destinations.
+
+// Boost Logging library
+//
+// 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
+
+
+/**
+@example no_levels_with_route.cpp
+
+@copydoc no_levels_with_route
+
+@page no_levels_with_route no_levels_with_route.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:
+@code
+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
+
+*/
+
+
+
+#define BOOST_LOGGING_COMPILE_FAST_OFF
+#include <boost/logging/logging.hpp>
+#include <boost/logging/format.hpp>
+
+using namespace boost::logging;
+
+typedef optimize::cache_string_several_str<> cache_string;
+
+// Step 1: specify your formatter & destination base classes
+typedef formatter::base< cache_string& > formatter_base;
+typedef destination::base< const std::string & > destination_base;
+
+// Step 2 : define your logging class(es)
+typedef logger< use_format_write<formatter_base,destination_base> > log_type;
+
+// Step 3 : Set up a filter
+filter::no_ts g_log_filter ;
+
+// Step 4: declare which loggers you'll use
+BOOST_DECLARE_LOG(g_l, log_type) // normally this goes into a header file ;)
+
+// Step 5: define which loggers you'll use
+BOOST_DEFINE_LOG(g_l, log_type)
+
+// Step 6: define the macros through which you'll log
+#define L_ BOOST_LOG_USE_LOG_IF_FILTER(g_l, g_log_filter.is_enabled() )
+
+void test_mul_levels_one_logger() {
+ // Step 7: 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_enter() );
+
+ // ... 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_enter() )
+ .fmt( formatter::idx() )
+ .clear()
+ .fmt( formatter::time("$hh:$mm.$ss ") )
+ .fmt( formatter::append_enter() )
+ .dest( destination::dbg_window() )
+ .clear()
+ .fmt( formatter::idx() )
+ .fmt( formatter::time("$hh:$mm.$ss ") )
+ .fmt( formatter::append_enter() )
+ .dest( destination::cout() )
+ .clear()
+ .fmt( formatter::idx() )
+ .fmt( formatter::append_enter() )
+ .dest( destination::file("out.txt") );
+
+ // Step 8: use it...
+ 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++;
+
+ // Step 9 : Enjoy!
+}
+
+
+
+#ifdef SINGLE_TEST
+
+int main() {
+ test_mul_levels_one_logger();
+}
+
+#endif
+
+// End of file
+

Modified: sandbox/logging/lib/logging/samples/vc8/loggingvc8/loggingvc8.vcproj
==============================================================================
--- sandbox/logging/lib/logging/samples/vc8/loggingvc8/loggingvc8.vcproj (original)
+++ sandbox/logging/lib/logging/samples/vc8/loggingvc8/loggingvc8.vcproj 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -438,6 +438,14 @@
                                 <File
                                         RelativePath="..\..\scenarios\mul_levels_mul_logers.cpp"
>
+ <FileConfiguration
+ Name="Test|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
                                 </File>
                                 <File
                                         RelativePath="..\..\scenarios\mul_levels_one_logger.cpp"
@@ -451,6 +459,17 @@
                                                 />
                                         </FileConfiguration>
                                 </File>
+ <File
+ RelativePath="..\..\scenarios\no_levels_with_route.cpp"
+ >
+ <FileConfiguration
+ Name="Test|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
                         </Filter>
                 </Filter>
                 <Filter

Modified: sandbox/logging/lib/logging/src/changelog.txt
==============================================================================
--- sandbox/logging/lib/logging/src/changelog.txt (original)
+++ sandbox/logging/lib/logging/src/changelog.txt 2007-10-22 05:37:31 EDT (Mon, 22 Oct 2007)
@@ -1,4 +1,7 @@
 
+v0.8.2, 22 oct 2007
+- added one more common scenario (with_route)
+
 
 v0.8.1, 22 oct 2007
 - added one more common scenario


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