Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2007-11-08 08:57:45


Author: jtorjo
Date: 2007-11-08 08:57:43 EST (Thu, 08 Nov 2007)
New Revision: 40929
URL: http://svn.boost.org/trac/boost/changeset/40929

Log:
[logging]
v0.10.12, 8 nov 2007
- added tss_resource_once_init and correspondent filter/logger class
- added scenario.hpp + documentation for it

Added:
   sandbox/logging/lib/logging/samples/scenarios/your_scenario.cpp (contents, props changed)
Text files modified:
   sandbox/logging/boost/logging/detail/format_write_detail.hpp | 7
   sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp | 4
   sandbox/logging/boost/logging/detail/raw_doc/scenarios.hpp | 6
   sandbox/logging/boost/logging/detail/raw_doc/scenarios_code.hpp | 9 +
   sandbox/logging/boost/logging/detail/raw_doc/table_of_contents.hpp | 1
   sandbox/logging/boost/logging/detail/ts/ts_resource.hpp | 36 ++++
   sandbox/logging/boost/logging/detail/use_format_write.hpp | 62 +++----
   sandbox/logging/boost/logging/filter.hpp | 4
   sandbox/logging/boost/logging/format.hpp | 10
   sandbox/logging/boost/logging/format_fwd.hpp | 25 ++
   sandbox/logging/boost/logging/level.hpp | 4
   sandbox/logging/boost/logging/macros.hpp | 24 --
   sandbox/logging/boost/logging/scenario.hpp | 310 ++++++++++++++++++++++++++++++++++++---
   sandbox/logging/lib/logging/internal/vc8/loggingvc8/loggingvc8.vcproj | 26 +++
   sandbox/logging/lib/logging/samples/scenarios/mul_levels_mul_logers.cpp | 4
   sandbox/logging/lib/logging/tests/do_not_use/testfast.cpp | 140 ++++++++++++-----
   16 files changed, 524 insertions(+), 148 deletions(-)

Modified: sandbox/logging/boost/logging/detail/format_write_detail.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/format_write_detail.hpp (original)
+++ sandbox/logging/boost/logging/detail/format_write_detail.hpp 2007-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -112,6 +112,8 @@
 
 @param destination_base The base class for all destination classes from your application. See manipulator.
 
+@param lock_resource How will we lock important resources - routing them (msg_route)
+
 @param apply_format_and_write [optional] The class that knows how to call the formatters and destinations. See @ref apply_format_and_write_object
 
 @param router_type [optional] The class that knows when to call the formatters, and when to call the destinations. See @ref object_router.
@@ -125,9 +127,10 @@
 */
 template<
         class formatter_base,
- class destination_base,
+ class destination_base,
+ class lock_resource = typename boost::logging::types<override>::lock_resource ,
         class apply_format_and_write = ::boost::logging::format_and_write::simple<typename formatter_base::raw_param>,
- class router_type = msg_route::simple<formatter_base, destination_base> ,
+ class router_type = msg_route::simple<formatter_base, destination_base, lock_resource> ,
         class formatter_array = array::shared_ptr_holder<formatter_base> ,
         class destination_array = array::shared_ptr_holder<destination_base> >
 struct format_write {

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 2007-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -1,9 +1,9 @@
 /**
 @page page_changelog Changelog
 
-v0.10.11, 8 nov 2007
+v0.10.12, 8 nov 2007
 - added tss_resource_once_init and correspondent filter/logger class
-- added scenario.hpp - not tested yet
+- added scenario.hpp + documentation for it
 - added and tested thread-safety (ts_write/on_dedicated_thread) for logger_format_write<>
 - added 2 more scenarios: ts_loger_one_filter.cpp and ded_loger_one_filter.cpp
 

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-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -6,6 +6,7 @@
 - @ref common_scenarios_1
 - @ref common_scenarios_2
 - @ref common_scenarios_3
+- @ref common_your_scenario
 - @ref common_scenarios_4
 - @ref common_scenarios_5
 - @ref common_scenarios_6
@@ -95,7 +96,12 @@
 \n\n\n
 
 
+@section common_your_scenario Your Scenario : Find out logger and filter, based on your application's needs
 
+@copydoc your_scenario
+
+@ref common_your_scenario_code "Click to see the code"
+\n\n\n
 
 
 

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-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -11,7 +11,7 @@
 - @ref scenarios_code_6
 - @ref scenarios_code_7
 - @ref scenarios_code_8
-
+- @ref common_your_scenario_code
 
 \n\n\n
 @section scenarios_code_1 Scenario 1, Common usage: Multiple levels, One logging class, Multiple destinations.
@@ -70,6 +70,13 @@
 \n\n\n
 
 
+
+
+@section common_your_scenario_code Your Scenario : Find out logger and filter, based on your application's needs
+
+@include your_scenario.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-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -11,6 +11,7 @@
     - @ref common_scenarios_1
     - @ref common_scenarios_2
     - @ref common_scenarios_3
+ - @ref common_your_scenario
     - @ref common_scenarios_4
     - @ref common_scenarios_5
     - @ref common_scenarios_6

Modified: sandbox/logging/boost/logging/detail/ts/ts_resource.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/ts/ts_resource.hpp (original)
+++ sandbox/logging/boost/logging/detail/ts/ts_resource.hpp 2007-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -108,6 +108,40 @@
     };
 
 
+ template<class type> struct ts_resource_single_thread {
+ typedef ts_resource_single_thread<type> self_type;
+
+ ts_resource_single_thread(const type& val = type() ) : m_val(val) {}
+
+ struct read;
+ struct write;
+ friend struct read;
+ friend struct write;
+
+ struct write {
+ self_type & self ;
+ write(self_type & self) : self(self) {
+ }
+ ~write() {
+ }
+
+ type & use() { return self.m_val ; }
+ type* operator->() { return &use(); }
+ };
+
+ struct read {
+ const self_type & self ;
+ read(const self_type & self) : self(self) {
+ }
+ ~read() {
+ }
+
+ const type & use() { return self.m_val ; }
+ const type* operator->() { return &use(); }
+ };
+ private:
+ type m_val;
+ };
 
 
 #ifndef BOOST_LOG_NO_TSS
@@ -240,7 +274,7 @@
                 cached_value & cached = *(self.m_cache);
                 val = &cached.val;
                 if ( !cached.is_cached) {
- mutex::scoped_lock lk(self.m_cs);
+ typename mutex::scoped_lock lk(self.m_cs);
                     if ( self.m_initialized) {
                         cached.val = self.m_val;
                         cached.is_cached = true;

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-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -34,22 +34,6 @@
 
 namespace boost { namespace logging {
 
-namespace writer {
- template<class msg_type, class base_type> struct on_dedicated_thread ;
- template<class base_type> struct ts_write ;
-
- /**
- @brief specify thread-safety of your logger_format_write class
- */
- namespace threading {
- /** @brief not thread-safe */
- struct no_ts {};
- /** @brief thread-safe write. All writes are protected by a lock */
- struct ts_write {};
- /** @brief thread-safe write on a dedicated thread. Very efficient. Formatting & writing to destinations happens on the dedicated thread */
- struct on_dedicated_thread {};
- }
-}
 
 
 
@@ -59,17 +43,17 @@
 
     namespace detail {
 
- template<class string, class formatter_base, class destination_base> struct find_format_write_params {
+ template<class string, class formatter_base, class destination_base, class lock_resource> 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;
+ typedef typename msg_route::simple<formatter_base, destination_base, lock_resource> 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>
+ template<class string_type, class formatter_base, class destination_base, class lock_resource>
+ struct find_format_write_params< typename boost::logging::optimize::cache_string_several_str<string_type>, formatter_base, destination_base, lock_resource>
         {
             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;
+ typedef typename msg_route::with_route<formatter_base, destination_base, lock_resource> router_type;
         };
 
         template<class thread_safety, class gather_type, class format_write> struct find_writer_with_thread_safety {
@@ -103,18 +87,20 @@
 template<
             class format_base_type ,
             class destination_base_type ,
- class gather
+ class gather ,
+ class lock_resource
>
 struct use_format_write {
 
     typedef typename use_default<format_base_type, boost::logging::formatter::base<> > ::type format_base;
     typedef typename use_default<destination_base_type, boost::logging::destination::base<> > ::type destination_base;
+ typedef typename use_default<lock_resource, ::boost::logging::types<override>::lock_resource> ::type lock_resource_type;
 
     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;
+ typedef typename detail::find_format_write_params<format_param, format_base, destination_base, lock_resource_type >::apply_format_and_write apply_format_and_write;
+ typedef typename detail::find_format_write_params<format_param, format_base, destination_base, lock_resource_type >::router_type router_type;
 };
 
 
@@ -142,32 +128,34 @@
 @param thread_safety
 @param gather
 */
-template<class format_base, class destination_base, class thread_safety, class gather>
+template<class format_base, class destination_base, class thread_safety, class gather, class lock_resource>
 struct logger_format_write
     : logger<
- typename use_format_write<format_base, destination_base, gather>::gather_type,
+ typename use_format_write<format_base, destination_base, gather, lock_resource>::gather_type,
             typename detail::find_writer_with_thread_safety<
                 thread_safety,
- typename use_format_write<format_base, destination_base, gather>::gather_type,
+ typename use_format_write<format_base, destination_base, gather, lock_resource>::gather_type,
                 writer::format_write<
- typename use_format_write<format_base, destination_base, gather>::format_base,
- typename use_format_write<format_base, destination_base, gather>::destination_base,
- typename use_format_write<format_base, destination_base, gather>::apply_format_and_write,
- typename use_format_write<format_base, destination_base, gather>::router_type
+ typename use_format_write<format_base, destination_base, gather, lock_resource>::format_base,
+ typename use_format_write<format_base, destination_base, gather, lock_resource>::destination_base,
+ typename use_format_write<format_base, destination_base, gather, lock_resource>::lock_resource_type,
+ typename use_format_write<format_base, destination_base, gather, lock_resource>::apply_format_and_write,
+ typename use_format_write<format_base, destination_base, gather, lock_resource>::router_type
>
>::type
>
 {
     typedef logger<
- typename use_format_write<format_base, destination_base, gather>::gather_type,
+ typename use_format_write<format_base, destination_base, gather, lock_resource>::gather_type,
             typename detail::find_writer_with_thread_safety<
                 thread_safety,
- typename use_format_write<format_base, destination_base, gather>::gather_type,
+ typename use_format_write<format_base, destination_base, gather, lock_resource>::gather_type,
                 writer::format_write<
- typename use_format_write<format_base, destination_base, gather>::format_base,
- typename use_format_write<format_base, destination_base, gather>::destination_base,
- typename use_format_write<format_base, destination_base, gather>::apply_format_and_write,
- typename use_format_write<format_base, destination_base, gather>::router_type
+ typename use_format_write<format_base, destination_base, gather, lock_resource>::format_base,
+ typename use_format_write<format_base, destination_base, gather, lock_resource>::destination_base,
+ typename use_format_write<format_base, destination_base, gather, lock_resource>::lock_resource_type,
+ typename use_format_write<format_base, destination_base, gather, lock_resource>::apply_format_and_write,
+ typename use_format_write<format_base, destination_base, gather, lock_resource>::router_type
>
>::type
>

Modified: sandbox/logging/boost/logging/filter.hpp
==============================================================================
--- sandbox/logging/boost/logging/filter.hpp (original)
+++ sandbox/logging/boost/logging/filter.hpp 2007-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -173,11 +173,11 @@
 
     use_tss_with_cache(int cache_secs = default_cache_secs) : m_enabled(true, cache_secs) {}
     bool is_enabled() const {
- data::read enabled(m_enabled);
+ typename data::read enabled(m_enabled);
         return enabled.use();
     }
     void set_enabled(bool enabled) {
- data::write cur(m_enabled);
+ typename data::write cur(m_enabled);
         cur.use() = enabled;
     }
 private:

Modified: sandbox/logging/boost/logging/format.hpp
==============================================================================
--- sandbox/logging/boost/logging/format.hpp (original)
+++ sandbox/logging/boost/logging/format.hpp 2007-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -263,7 +263,8 @@
     */
     template<
             class formatter_base,
- class destination_base >
+ class destination_base,
+ class lock_resource = typename boost::logging::types<override>::lock_resource >
     struct simple {
         typedef typename formatter_base::ptr_type formatter_ptr;
         typedef typename destination_base::ptr_type destination_ptr;
@@ -275,7 +276,7 @@
             d_array destinations;
         };
 
- typedef typename boost::logging::types<override>::lock_resource::finder<write_info>::type data;
+ typedef typename lock_resource::template finder<write_info>::type data;
 
         template<class formatter_array, class destination_array> simple(const formatter_array&, const destination_array&) {}
         
@@ -352,6 +353,7 @@
     template<
             class formatter_base,
             class destination_base,
+ class lock_resource = typename boost::logging::types<override>::lock_resource ,
             class formatter_array = boost::logging::array::shared_ptr_holder<formatter_base>,
             class destination_array = boost::logging::array::shared_ptr_holder<destination_base>
>
@@ -361,7 +363,7 @@
 
         typedef formatter_and_destination_array_holder<formatter_array, destination_array> holder_base_type;
 
- typedef with_route<formatter_base, destination_base, formatter_array, destination_array> self_type;
+ typedef with_route<formatter_base, destination_base, lock_resource, formatter_array, destination_array> self_type;
 
         typedef std::vector<formatter_ptr> f_array;
         typedef std::vector<destination_ptr> d_array;
@@ -374,7 +376,7 @@
             bool do_clear_afterwards;
         };
         typedef std::vector<write_once> write_array;
- typedef typename boost::logging::types<override>::lock_resource::finder<write_array>::type data;
+ typedef typename lock_resource::template finder<write_array>::type data;
 
     public:
         with_route(const formatter_array& formatters, const destination_array & destinations) : holder_base_type(formatters, destinations) {}

Modified: sandbox/logging/boost/logging/format_fwd.hpp
==============================================================================
--- sandbox/logging/boost/logging/format_fwd.hpp (original)
+++ sandbox/logging/boost/logging/format_fwd.hpp 2007-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -28,6 +28,23 @@
 
 namespace boost { namespace logging {
 
+namespace writer {
+ template<class msg_type, class base_type> struct on_dedicated_thread ;
+ template<class base_type> struct ts_write ;
+
+ /**
+ @brief specify thread-safety of your logger_format_write class
+ */
+ namespace threading {
+ /** @brief not thread-safe */
+ struct no_ts {};
+ /** @brief thread-safe write. All writes are protected by a lock */
+ struct ts_write {};
+ /** @brief thread-safe write on a dedicated thread. Very efficient. Formatting & writing to destinations happens on the dedicated thread */
+ struct on_dedicated_thread {};
+ }
+}
+
 /**
 @file boost/logging/format_fwd.hpp
 
@@ -64,19 +81,21 @@
 #endif
 @endcode
 */
-
 template<
             class format_base_type = default_,
             class destination_base_type = default_ ,
             class thread_safety = default_ ,
- class gather = default_
+ class gather = default_,
+ class lock_resource = default_
> struct logger_format_write;
 
 
+
+
 }}
 
 
-//#include <boost/logging/scenario.hpp>
+#include <boost/logging/scenario.hpp>
 
 #endif
 

Modified: sandbox/logging/boost/logging/level.hpp
==============================================================================
--- sandbox/logging/boost/logging/level.hpp (original)
+++ sandbox/logging/boost/logging/level.hpp 2007-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -132,11 +132,11 @@
 
         holder_tss_with_cache(int cache_secs = default_cache_secs, type default_level = enable_all) : m_level(default_level, cache_secs) {}
         bool is_enabled(type test_level) const {
- data::read cur_level(m_level);
+ typename data::read cur_level(m_level);
             return test_level >= cur_level.use();
         }
         void set_enabled(type level) {
- data::write cur_level(m_level);
+ typename data::write cur_level(m_level);
             cur_level.use() = level;
         }
     private:

Modified: sandbox/logging/boost/logging/macros.hpp
==============================================================================
--- sandbox/logging/boost/logging/macros.hpp (original)
+++ sandbox/logging/boost/logging/macros.hpp 2007-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -143,36 +143,18 @@
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Filter Macros
 
-#define BOOST_DECLARE_LOG_FILTER_NO_NAMESPACE_PREFIX(name,type) type& name ## _boost_log_filter_impl_(); extern boost::logging::detail::log_filter_keeper<type, name ## _boost_log_filter_impl_ > name;
-#define BOOST_DEFINE_LOG_FILTER_NO_NAMESPACE_PREFIX(name,type) type& name ## _boost_log_filter_impl_() \
+#define BOOST_DECLARE_LOG_FILTER(name,type) type& name ## _boost_log_filter_impl_(); extern boost::logging::detail::log_filter_keeper<type, name ## _boost_log_filter_impl_ > name;
+#define BOOST_DEFINE_LOG_FILTER(name,type) type& name ## _boost_log_filter_impl_() \
     { static type i; return i; } \
     namespace { boost::logging::detail::fake_using_log ensure_log_is_created_before_main ## name ( name ## _boost_log_filter_impl_() ); } \
     boost::logging::detail::log_filter_keeper<type, name ## _boost_log_filter_impl_ > name;
 
-#define BOOST_DEFINE_LOG_FILTER_NO_NAMESPACE_PREFIX_WITH_ARGS(name,type, args) type& name ## _boost_log_filter_impl_() \
+#define BOOST_DEFINE_LOG_FILTER_WITH_ARGS(name,type, args) type& name ## _boost_log_filter_impl_() \
     { static type i ( args ); return i; } \
     namespace { boost::logging::detail::fake_using_log ensure_log_is_created_before_main ## name ( name ## _boost_log_filter_impl_() ); } \
     boost::logging::detail::log_filter_keeper<type, name ## _boost_log_filter_impl_ > name;
 
 
-/**
-_at_note
- It is assumed that @c type is a filter class from the @c boost::logging namespace.
- In case you're creating your own filter class, make sure to have it in the boost::logging namespace. \n
- Or, you can use the BOOST_DECLARE_LOG_FILTER_NO_NAMESPACE_PREFIX macro instead
-*/
-#define BOOST_DECLARE_LOG_FILTER(name,type) BOOST_DECLARE_LOG_FILTER_NO_NAMESPACE_PREFIX(name, ::boost::logging:: type)
-
-/**
-_at_note
- It is assumed that @c type is a filter class from the @c boost::logging namespace.
- In case you're creating your own filter class, make sure to have it in the boost::logging namespace. \n
- Or, you can use the BOOST_DEFINE_LOG_FILTER_NO_NAMESPACE_PREFIX macro instead.
-*/
-#define BOOST_DEFINE_LOG_FILTER(name,type) BOOST_DEFINE_LOG_FILTER_NO_NAMESPACE_PREFIX(name, ::boost::logging:: type)
-
-#define BOOST_DEFINE_LOG_FILTER_WITH_ARGS(name,type, args) BOOST_DEFINE_LOG_FILTER_NO_NAMESPACE_PREFIX_WITH_ARGS(name, ::boost::logging:: type, args)
-
 
 
 

Modified: sandbox/logging/boost/logging/scenario.hpp
==============================================================================
--- sandbox/logging/boost/logging/scenario.hpp (original)
+++ sandbox/logging/boost/logging/scenario.hpp 2007-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -1,4 +1,4 @@
-// Template.hpp
+// scenario.hpp
 
 // Boost Logging library
 //
@@ -14,8 +14,8 @@
 // See http://www.torjo.com/log2/ for more details
 
 
-#ifndef JT28092007_TEMPLATE_HPP_DEFINED
-#define JT28092007_TEMPLATE_HPP_DEFINED
+#ifndef JT28092007_scenario_HPP_DEFINED
+#define JT28092007_scenario_HPP_DEFINED
 
 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
 # pragma once
@@ -24,7 +24,41 @@
 #include <boost/logging/detail/fwd.hpp>
 
 namespace boost { namespace logging {
+/** @page your_scenario_examples Examples of customizing your scenario
 
+Example 1:
+- Use a filter that uses per-thread caching with resync once at 10 secs,
+- The filter uses levels
+- Use a logger that will favor speed
+
+@code
+using namespace boost::logging::scenario::usage;
+typedef use< filter_::change::often<10>, filter_::level::use_levels, default_, logger_::favor::speed> finder;
+
+BOOST_DECLARE_LOG_FILTER(g_log_filter, finder::filter);
+BOOST_DECLARE_LOG(g_l, finder::logger)
+...
+@endcode
+
+
+Example 2:
+- Use a filter that is initialized only once, when multiple threads are running
+- The filter does not use levels
+- Use a logger that is initialized only once, when only one thread is running
+
+@code
+using namespace boost::logging::scenario::usage;
+typedef use< filter_::change::set_once_when_multiple_threads, filter_::level::no_levels, logger_::change::set_once_when_one_thread> finder;
+
+BOOST_DECLARE_LOG_FILTER(g_log_filter, finder::filter);
+BOOST_DECLARE_LOG(g_l, finder::logger)
+...
+@endcode
+
+To see scenario::usage used in code:
+- @ref common_your_scenario "Click to see description of the example"
+- @ref common_your_scenario_code "Click to see the code"
+*/
 
 namespace filter {
     template<int> struct use_tss_with_cache ;
@@ -39,17 +73,37 @@
     struct holder_ts;
     struct holder_no_ts ;
 }
-
+namespace writer {
+ namespace threading {
+ struct no_ts ;
+ struct ts_write ;
+ struct on_dedicated_thread ;
+ }
+}
 
 /**
- @brief Use it when you have a specific scenario, and want the best logger/filter classes for the scenario. Check out scenario::usage
+@brief Use this when you have a specific scenario, and want the best logger/filter classes that fit that scenario. Check out scenario::usage and scenario::ts.
+
+For example, if you want to specify a %scenario based on usage:
+
+@copydoc your_scenario_examples
+
 */
 namespace scenario {
 
 /**
- @brief Find out the right logger/filter, based on how your application will use the loggers and filters
+@brief If you want the library to choose the best logger/filter classes based on how your application will %use the loggers and filters, %use this namespace.
+
+First, don't forget to
+
+@code
+using namespace boost::logging::scenario::usage;
+@endcode
+
+Then, you can specify the logger and filter, in a very easy manner
+
+@copydoc your_scenario_examples
 
- First, don't forget to \n <tt>use namespace boost::logging::scenario::usage;</tt>
 */
 namespace usage {
 
@@ -117,9 +171,7 @@
         adding/removing formatters/destinations for instance.
         */
         namespace change {
- /** @brief Optimize for often change. Does per-thread caching. At a given period, it re-synchronizes.
-
- This is the default, for a multi-threaded application.
+ /** @brief Optimize for often change. Does per-thread caching. At a given period, it re-synchronizes. This is the default, for multi-threaded applications.
 
                 @param cache_period_secs At what period should we re-syncronize
             */
@@ -142,9 +194,7 @@
             */
             struct always_accurate {};
 
- /** @brief Single threading. It doesn't matter when/how often the filter/logger changes.
-
- This is the default, for a single-threaded application.
+ /** @brief Single threading. It doesn't matter when/how often the filter/logger changes. This is the default, for single-threaded applications.
             */
             struct single_thread {};
 
@@ -165,13 +215,30 @@
             */
             struct speed {};
 
- /** @brief all messages will be logged
-
- This is the default
+ /** @brief All messages will be logged. This is the default for multi-threaded application
             */
             struct correctness {};
 
+ /** @brief Single threading. It doesn't matter when/how often the filter/logger changes. This is the default, for single-threaded applications.
+ */
+ struct single_thread {};
+
+#ifdef BOOST_HAS_THREADS
             typedef correctness default_;
+#else
+ typedef single_thread default_;
+#endif
+ };
+
+ /** @brief How do you gather the message? */
+ namespace gather {
+ /** @brief Using the cool operator<< (default) */
+ struct ostream_like {};
+
+ /** @brief If you want to use your custom class, specify it here */
+ template<class gather_type> struct custom {};
+
+ typedef ostream_like default_;
         };
     }
 
@@ -185,8 +252,8 @@
 
         template<class change_> struct find_filter_use_levels {};
         
- template<int period_ms> struct find_filter_use_levels< change::often<period_ms> > {
- typedef ::boost::logging::level::holder_tss_with_cache<period_ms> type;
+ template<int period_secs> struct find_filter_use_levels< change::often<period_secs> > {
+ typedef ::boost::logging::level::holder_tss_with_cache<period_secs> type;
         };
 
         template<> struct find_filter_use_levels< change::set_once_when_one_thread > {
@@ -211,8 +278,8 @@
 
         template<class change_> struct find_filter_no_levels {};
         
- template<int period_ms> struct find_filter_no_levels< change::often<period_ms> > {
- typedef ::boost::logging::filter::use_tss_with_cache<period_ms> type;
+ template<int period_secs> struct find_filter_no_levels< change::often<period_secs> > {
+ typedef ::boost::logging::filter::use_tss_with_cache<period_secs> type;
         };
 
         template<> struct find_filter_no_levels< change::set_once_when_one_thread > {
@@ -248,40 +315,229 @@
     namespace detail_find_logger {
         namespace favor = ::boost::logging::scenario::usage::logger_::favor;
         namespace change = ::boost::logging::scenario::usage::logger_::change;
+ namespace th = ::boost::logging::writer::threading;
+ namespace gather_usage = ::boost::logging::scenario::usage::logger_::gather;
+
+ template<class favor_> struct find_threading_from_favor {};
+ template<> struct find_threading_from_favor<favor::speed> { typedef th::on_dedicated_thread type; };
+ template<> struct find_threading_from_favor<favor::correctness> { typedef th::ts_write type; };
+ template<> struct find_threading_from_favor<favor::single_thread> { typedef th::no_ts type; };
+
+ template<class gather_type> struct find_gather {};
+ template<> struct find_gather<gather_usage::ostream_like> { typedef ::boost::logging::default_ type; };
+ template<class custom_gather> struct find_gather<gather_usage::custom<custom_gather> > { typedef custom_gather type; };
+
+ template<class favor_, class change_, class gather> struct find_logger {};
+
+ template<class favor_, int period_secs, class gather> struct find_logger< favor_, change::often<period_secs>, gather > {
+ typedef typename find_threading_from_favor<favor_>::type threading_type;
+ template<int secs> struct lock_resource {
+ template<class lock_type> struct finder {
+ typedef typename ::boost::logging::locker::tss_resource_with_cache<lock_type, secs, boost::logging::threading::mutex > type;
+ };
+ };
+
+ typedef ::boost::logging::logger_format_write < default_, default_, threading_type, gather, lock_resource<period_secs> > type;
+ };
+
+ template<class favor_, class gather> struct find_logger< favor_, change::set_once_when_one_thread, gather > {
+ typedef typename find_threading_from_favor<favor_>::type threading_type;
+ struct lock_resource {
+ template<class lock_type> struct finder {
+ typedef typename locker::ts_resource_single_thread<lock_type> type;
+ };
+ };
+
+ typedef ::boost::logging::logger_format_write< default_, default_, threading_type, gather, lock_resource> type;
+ };
+
+ template<class favor_, class gather> struct find_logger< favor_, change::set_once_when_multiple_threads, gather > {
+ typedef typename find_threading_from_favor<favor_>::type threading_type;
+ struct lock_resource {
+ template<class lock_type> struct finder {
+ typedef typename locker::tss_resource_once_init<lock_type, boost::logging::threading::mutex > type;
+ };
+ };
+
+ typedef ::boost::logging::logger_format_write< default_, default_, threading_type, gather, lock_resource> type;
+ };
+
+ template<class favor_, class gather> struct find_logger< favor_, change::always_accurate, gather > {
+ typedef typename find_threading_from_favor<favor_>::type threading_type;
+ struct lock_resource {
+ template<class lock_type> struct finder {
+ typedef typename locker::ts_resource<lock_type, boost::logging::threading::mutex > type;
+ };
+ };
+
+ typedef ::boost::logging::logger_format_write< default_, default_, threading_type, gather, lock_resource> type;
+ };
+
+ template<class favor_, class gather> struct find_logger< favor_, change::single_thread, gather > {
+ typedef typename find_threading_from_favor<favor_>::type threading_type;
+ struct lock_resource {
+ template<class lock_type> struct finder {
+ typedef typename locker::ts_resource_single_thread<lock_type> type;
+ };
+ };
+
+ typedef ::boost::logging::logger_format_write< default_, default_, threading_type, gather, lock_resource> type;
+ };
     }
 
     /**
- @brief Finds a filter class and a logger class, based on your specific scenario
+ @brief Finds a filter class and a logger class that fit your application's needs
+
+ For this to happen, you will first need to specify your needs (the template parameters you'll pass to this class)
 
         @param filter_change (optional) How does the %filter change? Any of the classes in the filter_::change namespace
         @param filter_level_ (optional) Does our %filter %use levels? Any of the classes in the filter_::level namespace
         @param logger_change (optional) How does our %logger change? Any of the classes in the logger_::change namespace
         @param logger_favor (optional) What does the %logger favor? Any of the classes in the logger_::favor namespace
+ @param logger_gather (optional) What to %use as gather class. Any of the classes in the logger_::gather namespace
+
+ @copydoc your_scenario_examples
     */
     template<
         class filter_change = default_,
         class filter_level = default_,
         class logger_change = default_,
- class logger_favor = default_>
+ class logger_favor = default_,
+ class logger_gather = default_ >
     struct use {
 
+ private:
         typedef typename use_default<filter_change, filter_::change::default_ >::type filter_change_type;
         typedef typename use_default<filter_level, filter_::level::default_ >::type filter_level_type;
 
- typedef typename detail_find_filter::find_filter<filter_change_type, filter_level_type>::type filter;
+ typedef typename use_default<logger_change, logger_::change::default_ >::type logger_change_type;
+ typedef typename use_default<logger_favor, logger_::favor::default_>::type logger_favor_type;
+ typedef typename use_default<logger_gather, logger_::gather::default_>::type gather_usage_type;
+
+ typedef typename detail_find_logger::find_gather<gather_usage_type> ::type gather_type;
 
+ public:
+ typedef typename detail_find_filter::find_filter<filter_change_type, filter_level_type>::type filter;
+ typedef typename detail_find_logger::find_logger< logger_favor_type, logger_change_type, gather_type>::type logger;
 
-// typedef ... logger;
- // typedef ... filter;
     };
 }
 
 /**
- @brief Find out the right logger/filter, based on thread-safety of logger(s)/filter(s)
+@brief Find out the right logger/filter, based on thread-safety of logger(s)/filter(s)
+
+First, don't forget to
+
+@code
+using namespace boost::logging::scenario::ts;
+@endcode
 
- First, don't forget to <tt>use namespace boost::logging::scenario::ts;</tt>
+Then, you can specify the logger and filter, in a very easy manner
+
+Example:
+- Use a filter that uses TSS (Thread Specific Storage)
+- The filter uses levels
+- Use a logger that uses TSS
+
+@code
+using namespace boost::logging::scenario::ts;
+typedef use< filter_::use_tss, level_::use_levels, logger_::use_tss> finder;
+
+BOOST_DECLARE_LOG_FILTER(g_log_filter, finder::filter);
+BOOST_DECLARE_LOG(g_l, finder::logger)
+...
+@endcode
+
+
+To see how you can specify the logger/filter based on how you will %use them, see usage namespace.
 */
 namespace ts {
+ /** @brief filter uses levels? */
+ struct level_ {
+ /** @brief type of %filter levels %usage */
+ enum type {
+ /** @brief %use levels */
+ use_levels,
+ /** @brief don't %use levels */
+ no_levels
+ };
+ };
+
+ /** @brief filter thread-safety */
+ struct filter_ {
+ /** @brief type of filter thread-safety */
+ enum type {
+ /** @brief not thread-safe */
+ none,
+ /** @brief %use TSS (thread-specific storage) */
+ use_tss,
+ /** @brief thread-safe (but slow) */
+ ts
+ };
+ };
+
+ /** logger thread-safety */
+ struct logger_ {
+ /** @brief type of logger thread-safety */
+ enum type {
+ /** @brief not thread-safe */
+ none,
+ /** @brief %use TSS (thread-specific storage) */
+ use_tss,
+ /** @brief thread-safe (but slow) */
+ ts
+ };
+ };
+
+ namespace detail {
+ namespace th = ::boost::logging::writer::threading;
+
+ template<filter_::type,level_::type> struct find_filter {};
+ template<> struct find_filter<filter_::none, level_::no_levels > { typedef ::boost::logging::filter::no_ts type; };
+ template<> struct find_filter<filter_::use_tss, level_::no_levels> { typedef ::boost::logging::filter::use_tss_with_cache<5> type; };
+ template<> struct find_filter<filter_::ts, level_::no_levels> { typedef ::boost::logging::filter::ts type; };
+
+ template<> struct find_filter<filter_::none, level_::use_levels > { typedef ::boost::logging::level::holder_no_ts type; };
+ template<> struct find_filter<filter_::use_tss, level_::use_levels > { typedef ::boost::logging::level::holder_tss_with_cache<5> type; };
+ template<> struct find_filter<filter_::ts, level_::use_levels > { typedef ::boost::logging::level::holder_ts type; };
+
+ template<logger_::type> struct find_logger {};
+ template<> struct find_logger<logger_::none> {
+ struct lock_resource {
+ template<class lock_type> struct finder {
+ typedef typename locker::ts_resource_single_thread<lock_type> type;
+ };
+ };
+ typedef ::boost::logging::logger_format_write< default_, default_, th::no_ts, default_, lock_resource > type ;
+ };
+ template<> struct find_logger<logger_::use_tss> {
+ struct lock_resource {
+ template<class lock_type> struct finder {
+ typedef typename ::boost::logging::locker::tss_resource_with_cache<lock_type, 5, boost::logging::threading::mutex > type;
+ };
+ };
+
+ typedef ::boost::logging::logger_format_write< default_, default_, th::ts_write, default_, lock_resource > type ;
+ };
+ template<> struct find_logger<logger_::ts> {
+ struct lock_resource {
+ template<class lock_type> struct finder {
+ typedef typename locker::ts_resource<lock_type, boost::logging::threading::mutex > type;
+ };
+ };
+
+ typedef ::boost::logging::logger_format_write< default_, default_, th::ts_write, default_, lock_resource > type ;
+ };
+ }
+
+ /** @brief Find the right logger and filter, based on thread-safety: filter_::type, level_::type and logger_::type
+
+ @copydoc ts
+ */
+ template<filter_::type filter_type, level_::type level_type, logger_::type logger_type> struct use {
+ typedef typename detail::find_filter<filter_type,level_type>::type filter;
+ typedef typename detail::find_logger<logger_type>::type logger;
+ };
 }
 
 }

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 2007-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -1000,6 +1000,32 @@
                         <File
                                 RelativePath="..\..\..\samples\scenarios\ts_loger_one_filter.cpp"
>
+ <FileConfiguration
+ Name="Test|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="..\..\..\samples\scenarios\your_scenario.cpp"
+ >
+ <FileConfiguration
+ Name="Test|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="TestAll|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
                         </File>
                 </Filter>
         </Files>

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-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -91,7 +91,7 @@
 
 
 // Step 4: declare which filters and loggers you'll use (usually in a header file)
-BOOST_DECLARE_LOG_FILTER(g_log_level, level::holder ) // holds the application log level
+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)
@@ -102,7 +102,7 @@
 #define LAPP_ BOOST_LOG_USE_LOG_IF_LEVEL(g_log_app, g_log_level, info ) << "[app] "
 
 // Step 6: Define the filters and loggers you'll use (usually in a source file)
-BOOST_DEFINE_LOG_FILTER(g_log_level, level::holder ) // holds the application log level
+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)

Added: sandbox/logging/lib/logging/samples/scenarios/your_scenario.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/samples/scenarios/your_scenario.cpp 2007-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -0,0 +1,194 @@
+// your_scenario.cpp
+//
+// A test of the Logging library with multiple levels, multiple logging classes (each writing to multiple destinations) and one filter.
+// The logger and filter are specified using the boost::logging::scenario namespace
+
+// 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 your_scenario.cpp
+
+@copydoc your_scenario
+
+@page your_scenario your_scenario.cpp Example
+
+
+This usage:
+- You have several loggers
+- You have one filter, which can be turned on or off
+- You want to format the message before it's written
+- Each logger has several log destinations
+- The logger and filter are specified using the boost::logging::scenario namespace
+ - the filter is always accurate (but slow)
+ - the filter does not use levels
+ - the logger favors speed (on a dedicated thread)
+ - the logger is initialized once, when only one thread is running
+
+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 enter
+- Info output goes to console, and a file called out.txt
+ - formatting - prefix each message by time and append enter
+- Debug messages go to the debug output window, and the console
+ - formatting - prefix each message by time, and append enter
+
+
+Here's how the output will look like:
+
+The debug output window:
+@code
+18:59.24 this is so cool 1
+18:59.24 this is so cool again 2
+@endcode
+
+
+The console:
+@code
+18:59.24 this is so cool 1
+18:59.24 this is so cool again 2
+18:59.24 hello, world
+18:59.24 good to be back ;) 4
+@endcode
+
+
+The out.txt file:
+@code
+18:59.24 hello, world
+18:59.24 good to be back ;) 4
+@endcode
+
+
+The err.txt file
+@code
+18:59.24 [1] first error 3
+18:59.24 [2] second error 5
+@endcode
+*/
+
+
+
+#define BOOST_LOG_COMPILE_FAST_OFF
+#include <boost/logging/format_fwd.hpp>
+
+// Step 1: Optimize : use a cache string, to make formatting the message faster
+BOOST_LOG_FORMAT_MSG( optimize::cache_string_one_str<> )
+
+#include <boost/logging/format_ts.hpp>
+#include <boost/thread/xtime.hpp>
+using namespace boost::logging;
+
+// Step 3 : Specify your logging class(es)
+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;
+
+// Step 4: declare which filters and loggers you'll use (usually in a header file)
+BOOST_DECLARE_LOG_FILTER(g_log_filter, finder::filter )
+BOOST_DECLARE_LOG(g_log_err, finder::logger )
+BOOST_DECLARE_LOG(g_log_app, finder::logger )
+BOOST_DECLARE_LOG(g_log_dbg, finder::logger )
+
+// Step 5: define the macros through which you'll log
+#define LDBG_ BOOST_LOG_USE_LOG_IF_FILTER(g_log_dbg, g_log_filter->is_enabled() )
+#define LERR_ BOOST_LOG_USE_LOG_IF_FILTER(g_log_err, g_log_filter->is_enabled() )
+#define LAPP_ BOOST_LOG_USE_LOG_IF_FILTER(g_log_app, g_log_filter->is_enabled() )
+
+// Step 6: Define the filters and loggers you'll use (usually in a source file)
+BOOST_DEFINE_LOG_FILTER(g_log_filter, finder::filter )
+BOOST_DEFINE_LOG(g_log_err, finder::logger )
+BOOST_DEFINE_LOG(g_log_app, finder::logger )
+BOOST_DEFINE_LOG(g_log_dbg, finder::logger )
+
+void do_sleep(int ms) {
+ using namespace boost;
+ xtime next;
+ xtime_get( &next, TIME_UTC);
+ next.nsec += (ms % 1000) * 1000000;
+
+ int nano_per_sec = 1000000000;
+ next.sec += next.nsec / nano_per_sec;
+ next.sec += ms / 1000;
+ next.nsec %= nano_per_sec;
+ thread::sleep( next);
+}
+
+void your_scenario_example() {
+ // Step 7: add formatters and destinations
+ // That is, how the message is to be formatted and where should it be written to
+
+ // 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") );
+
+ // 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( destination::file("out.txt") );
+ 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( destination::dbg_window() );
+ g_log_dbg->writer().add_destination( destination::cout() );
+
+ // Step 8: use it...
+ 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;
+
+ g_log_filter->set_enabled(false);
+ LDBG_ << "this will not be written anywhere";
+ LAPP_ << "this won't be written anywhere either";
+ LERR_ << "this error is not logged " << i++;
+
+ g_log_filter->set_enabled(true);
+ LAPP_ << "good to be back ;) " << i++;
+ LERR_ << "second error " << i++;
+
+ // Step 9 : Enjoy!
+
+ // just so that we can see the output to the console as well (the messages are written no a different thread)...
+ do_sleep(1000);
+}
+
+
+
+#ifdef SINGLE_TEST
+
+int main() {
+ your_scenario_example();
+}
+
+#endif
+
+// End of file
+

Modified: sandbox/logging/lib/logging/tests/do_not_use/testfast.cpp
==============================================================================
--- sandbox/logging/lib/logging/tests/do_not_use/testfast.cpp (original)
+++ sandbox/logging/lib/logging/tests/do_not_use/testfast.cpp 2007-11-08 08:57:43 EST (Thu, 08 Nov 2007)
@@ -1,53 +1,109 @@
+// your_scenario.cpp
+//
+// A test of the Logging library with multiple levels, multiple logging classes (each writing to multiple destinations) and one filter.
+// The logger and filter are specified using the boost::logging::scenario namespace
+
+// 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 your_scenario.cpp
+
+@copydoc your_scenario
+
+@page your_scenario your_scenario.cpp Example
+
+
+This usage:
+- You have several loggers
+- You have one filter, which can be turned on or off
+- You want to format the message before it's written
+- Each logger has several log destinations
+- The logger and filter are specified using the boost::logging::scenario namespace
+ - the filter is always accurate (but slow)
+ - the filter does not use levels
+ - the logger favors speed (on a dedicated thread)
+ - the logger is initialized once, when only one thread is running
+
+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 enter
+- Info output goes to console, and a file called out.txt
+ - formatting - prefix each message by time and append enter
+- Debug messages go to the debug output window, and the console
+ - formatting - prefix each message by time, and append enter
+
+
+Here's how the output will look like:
+
+The debug output window:
+@code
+18:59.24 this is so cool 1
+18:59.24 this is so cool again 2
+@endcode
+
+
+The console:
+@code
+18:59.24 this is so cool 1
+18:59.24 this is so cool again 2
+18:59.24 hello, world
+18:59.24 good to be back ;) 4
+@endcode
+
+
+The out.txt file:
+@code
+18:59.24 hello, world
+18:59.24 good to be back ;) 4
+@endcode
+
+
+The err.txt file
+@code
+18:59.24 [1] first error 3
+18:59.24 [2] second error 5
+@endcode
+*/
 
-#define BOOST_LOG_COMPILE_FAST_ON
+
+
+#define BOOST_LOG_COMPILE_FAST_OFF
 #include <boost/logging/format_fwd.hpp>
 
 // Step 1: Optimize : use a cache string, to make formatting the message faster
 BOOST_LOG_FORMAT_MSG( optimize::cache_string_one_str<> )
 
-//#include <boost/logging/format.hpp>
-#include <boost/logging/writer/format_write.hpp>
-
+#include <boost/logging/format_ts.hpp>
 using namespace boost::logging;
 
 // Step 3 : Specify your logging class(es)
-typedef logger_format_write< > log_type;
-
-BOOST_DECLARE_LOG(g_l, log_type)
-
-
-// Step 4: declare which filters and loggers you'll use (usually in a header file)
-BOOST_DECLARE_LOG_FILTER(g_log_filter, filter::no_ts )
-BOOST_DECLARE_LOG(g_l, log_type)
-
-// Step 5: define the macros through which you'll log
-#define L_ BOOST_LOG_USE_LOG_IF_FILTER(g_l, g_log_filter->is_enabled() )
+// - the filter is always accurate (but slow)
+// - the filter does not use levels
+// - the logger favors speed (on a dedicated thread)
+// - the logger is initialized once, when only one thread is running
+using namespace boost::logging::scenario::usage;
+typedef use<filter_::change::always_accurate, filter_::level::no_levels, logger_::change::set_once_when_one_thread, logger_::favor::speed> finder;
 
 
-void one_logger_one_filter_example() {
- // Step 7: add formatters and destinations
- // That is, how the message is to be formatted and where should it be written to
-
- g_l->writer().add_formatter( formatter::idx() );
- g_l->writer().add_formatter( formatter::append_newline() );
- g_l->writer().add_destination( destination::file("out.txt") );
- g_l->writer().add_destination( destination::cout() );
- g_l->writer().add_destination( destination::dbg_window() );
-
- // Step 8: use it...
- 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 to the log";
- L_ << "this won't be written to the log";
-
- g_log_filter->set_enabled(true);
- L_ << "good to be back ;) " << i++;
+void your_scenario_example() {
+ finder ::filter f;
+ finder:: logger l;
+ int i = 0;
 }
 
 
@@ -55,14 +111,10 @@
 #ifdef SINGLE_TEST
 
 int main() {
- one_logger_one_filter_example();
+ your_scenario_example();
 }
 
 #endif
 
 // End of file
 
-// Step 6: Define the filters and loggers you'll use (usually in a source file)
-BOOST_DEFINE_LOG_FILTER(g_log_filter, filter::no_ts )
-BOOST_DEFINE_LOG(g_l, log_type)
-


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