Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2007-11-30 05:51:35


Author: jtorjo
Date: 2007-11-30 05:51:33 EST (Fri, 30 Nov 2007)
New Revision: 41490
URL: http://svn.boost.org/trac/boost/changeset/41490

Log:
[logging]
v0.12.5, 30 nov 2007
- added boost::logging::spacer
Added:
   sandbox/logging/boost/logging/format/formatter/named_spacer.hpp (contents, props changed)
   sandbox/logging/boost/logging/format/formatter/spacer.hpp (contents, props changed)
Text files modified:
   sandbox/logging/boost/logging/detail/format_write_detail.hpp | 22 +++++-
   sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp | 3
   sandbox/logging/boost/logging/detail/raw_doc/todo.hpp | 4
   sandbox/logging/boost/logging/format/formatter/defaults.hpp | 10 ++
   sandbox/logging/boost/logging/format/formatter/tags.hpp | 8 ++
   sandbox/logging/boost/logging/format/formatter/thread_id.hpp | 6 +
   sandbox/logging/boost/logging/format/formatter/time.hpp | 2
   sandbox/logging/lib/logging/internal/vc8/loggingvc8/loggingvc8.vcproj | 8 ++
   sandbox/logging/lib/logging/internal/vc8/loggingvc8/test_now.cpp | 134 ++++++++++++++++++---------------------
   9 files changed, 116 insertions(+), 81 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-30 05:51:33 EST (Fri, 30 Nov 2007)
@@ -200,7 +200,9 @@
 
 public:
     /**
- adds a formatter
+ @brief Adds a formatter
+
+ @param fmt The formatter
     */
     template<class formatter> void add_formatter(formatter fmt) {
         typedef boost::logging::manipulator::is_generic is_generic;
@@ -208,7 +210,19 @@
     }
 
     /**
- deletes a formatter
+ @brief Adds a formatter. Also, the second argument is the @ref boost::logging::formatter::spacer_t "spacer" string
+
+ @param fmt The formatter
+ @param format_str The @ref boost::logging::formatter::spacer_t "spacer" string
+ */
+ template<class formatter> void add_formatter(formatter fmt, const char_type * format_str) {
+ add_formatter( spacer(fmt, format_str) );
+ }
+
+ /**
+ @brief Deletes a formatter
+
+ @param fmt The formatter to delete
     */
     template<class formatter> void del_formatter(formatter fmt) {
         typedef boost::logging::manipulator::is_generic is_generic;
@@ -216,7 +230,7 @@
     }
 
     /**
- adds a destination
+ @brief Adds a destination
     */
     template<class destination> void add_destination(destination dest) {
         typedef boost::logging::manipulator::is_generic is_generic;
@@ -224,7 +238,7 @@
     }
 
     /**
- deletes a destination
+ @brief Deletes a destination
     */
     template<class destination> void del_destination(destination dest) {
         typedef boost::logging::manipulator::is_generic is_generic;

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-30 05:51:33 EST (Fri, 30 Nov 2007)
@@ -1,7 +1,8 @@
 /**
 @page page_changelog Changelog
 
-_at_section changelog_cur_ver Current Version: v0.12.4, 26 nov 2007
+@section changelog_cur_ver Current Version: v0.12.5, 30 nov 2007
+- added boost::logging::spacer
 - removed copyright from examples (scenarios) - so that they're easier to read in the documentation
 - added scoped logs
 - removed #ifdef SINGLE_TEST from scenarios

Modified: sandbox/logging/boost/logging/detail/raw_doc/todo.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/todo.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/todo.hpp 2007-11-30 05:51:33 EST (Fri, 30 Nov 2007)
@@ -27,7 +27,7 @@
 - @c high test TSS on vs2003 and gcc/pthreads \n
   (note: tested on pthreads; however - about internal implementation : 2 TSS objects are leaked on pthreads, need to see why)
 
-- @c high if *used* before main, it'll cache the messages, and then write them ASAP; \n
+- @c must_have if *used* before main, it'll cache the messages, and then write them ASAP; \n
     will have a func - like, do_write() - which will write all that was cached, and then turn cache off \n
     ----- i have to see if reasonable to later ask if a log is enabled or not, or just dump all messages written before initializing the log
 
@@ -85,6 +85,8 @@
   have a named formatter that can write more formatters at the same time, but based on name - make it easy to use, and somehow the default should
   encompass all existing formatters TOTHINK the problem is still setting params at the constructor of certain objects - like - time(%m:%s) etc.
   we should make it as easy as possible; perhaps make it very easy for named formatter - TOTHINK
+ maybe i can have an extra param as formatter - the "spacer" spacer<....>(construct - pass to it,"[%])
+ the named formatter - leave that "normal" for later
 
 - @c high new formatter - write a more "exact" time - up to the millisec or so; should use Boost.DateTime for higher-resolution timestamps.
 

Modified: sandbox/logging/boost/logging/format/formatter/defaults.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/formatter/defaults.hpp (original)
+++ sandbox/logging/boost/logging/format/formatter/defaults.hpp 2007-11-30 05:51:33 EST (Fri, 30 Nov 2007)
@@ -23,7 +23,9 @@
 
 #include <boost/logging/detail/fwd.hpp>
 #include <boost/logging/detail/manipulator.hpp>
+#include <boost/logging/format/formatter/convert_format.hpp>
 #include <boost/logging/format/formatter/time.hpp>
+#include <boost/logging/format/formatter/spacer.hpp>
 #include <stdio.h>
 #include <time.h>
 #include <sstream>
@@ -53,11 +55,12 @@
 */
 template<class convert = do_convert_format::prepend> struct idx_t : is_generic, formatter::non_const_context<int>, boost::logging::op_equal::always_equal {
     typedef formatter::non_const_context<int> non_const_context_base;
+ typedef convert convert_type;
 
     idx_t() : non_const_context_base((int)0) {}
     template<class msg_type> void operator()(msg_type & str) const {
         std::basic_ostringstream<char_type> idx;
- idx << BOOST_LOG_STR("[") << ++context() << BOOST_LOG_STR("] ");
+ idx << ++context() ;
 
         convert::write( idx.str(), str );
     }
@@ -71,6 +74,7 @@
 For instance, you might use @ref boost::logging::optimize::cache_string_one_str "a cached_string class" (see @ref boost::logging::optimize "optimize namespace").
 */
 template<class convert = do_convert_format::append> struct append_newline_t : is_generic, boost::logging::op_equal::always_equal {
+ typedef convert convert_type;
     template<class msg_type> void operator()(msg_type & str) const {
         convert::write( BOOST_LOG_STR("\n"), str );
     }
@@ -84,6 +88,8 @@
 For instance, you might use @ref boost::logging::optimize::cache_string_one_str "a cached_string class" (see @ref boost::logging::optimize "optimize namespace").
 */
 template<class convert = do_convert_format::append> struct append_newline_if_needed_t : is_generic, boost::logging::op_equal::always_equal {
+ typedef convert convert_type;
+
     template<class msg_type> void operator()(msg_type & str) const {
         bool is_needed = true;
         if ( ! convert::get_underlying_string(str).empty())
@@ -95,6 +101,8 @@
     }
 };
 
+
+
 /** @brief idx_t with default values. See idx_t
 
 @copydoc idx_t

Added: sandbox/logging/boost/logging/format/formatter/named_spacer.hpp
==============================================================================
--- (empty file)
+++ sandbox/logging/boost/logging/format/formatter/named_spacer.hpp 2007-11-30 05:51:33 EST (Fri, 30 Nov 2007)
@@ -0,0 +1,36 @@
+// named_spacer.hpp
+
+// 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
+
+
+#ifndef JT28092007_named_spacer_HPP_DEFINED
+#define JT28092007_named_spacer_HPP_DEFINED
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#include <boost/logging/detail/fwd.hpp>
+
+namespace boost { namespace logging { namespace formatter {
+
+ // when adding generic ones, make sure I keep the same convert (append or prepend)
+ // also, allow adding more in one step : .add(..).add(..)....
+
+
+
+}}}
+
+#endif
+

Added: sandbox/logging/boost/logging/format/formatter/spacer.hpp
==============================================================================
--- (empty file)
+++ sandbox/logging/boost/logging/format/formatter/spacer.hpp 2007-11-30 05:51:33 EST (Fri, 30 Nov 2007)
@@ -0,0 +1,179 @@
+// spacer.hpp
+
+// 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
+
+
+#ifndef JT28092007_spacer_HPP_DEFINED
+#define JT28092007_spacer_HPP_DEFINED
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#include <boost/logging/detail/fwd.hpp>
+#include <boost/type_traits/is_base_of.hpp>
+#include <boost/logging/format/formatter/convert_format.hpp>
+
+namespace boost { namespace logging { namespace formatter {
+
+namespace detail {
+
+ template<class original_formatter, class msg_type, class string_type> inline void spacer_write_with_convert(msg_type & msg, const original_formatter & fmt, const string_type & prefix, const string_type & suffix, const do_convert_format::prepend*) {
+ // prepend
+ do_convert_format::prepend::write(suffix, msg);
+ fmt(msg);
+ do_convert_format::prepend::write(prefix, msg);
+ }
+ template<class original_formatter, class msg_type, class string_type> inline void spacer_write_with_convert(msg_type & msg, const original_formatter & fmt, const string_type & prefix, const string_type & suffix, const do_convert_format::append*) {
+ // append
+ do_convert_format::append::write(prefix, msg);
+ fmt(msg);
+ do_convert_format::append::write(suffix, msg);
+ }
+ template<class original_formatter, class msg_type, class string_type, class convert> inline void spacer_write_with_convert(msg_type & msg, const original_formatter & fmt, const string_type & prefix, const string_type & suffix, const convert*) {
+ // custom conversion - prefix before suffix
+ convert::write(prefix, msg);
+ fmt(msg);
+ convert::write(suffix, msg);
+ }
+
+ // note: pass original_formatter here - so that original_formatter::operator() gets called, not the spacer_t's operator()
+ template<class original_formatter, class convert, class msg_type, class string_type> inline void spacer_write(msg_type & msg, const original_formatter & fmt, const string_type & prefix, const string_type & suffix) {
+ spacer_write_with_convert(msg, fmt, prefix, suffix, (const convert*)0);
+ }
+}
+
+/** @brief Prepends some info, and appends some info to an existing formatter
+
+The syntax is simple: construct a spacer by passing the original formatter, and the text to space (prepend and append).
+Use:
+- @c % to mean the original formatter text
+- anything before @c "%" is prepended before
+- anything after @c "%" is appended after
+
+Examples:
+
+@code
+// prefix "[" before index, and append "] " after it.
+formatter::spacer( formatter::idx(), "[%] ");
+
+// prefix "{T" before thread_id, and append "} " after it
+formatter::spacer( formatter::thread_id(), "{T%} ");
+@endcode
+
+When adding a spacer formatter, you'll do something similar to:
+
+@code
+g_l->writer().add_formatter( formatter::spacer( formatter::idx(), "[%] ") );
+@endcode
+
+However, to make this even simpler, I allow an ever easier syntax:
+
+@code
+// equivalent to the above
+g_l->writer().add_formatter( formatter::idx(), "[%] " );
+@endcode
+
+
+*/
+template<class convert, class original_formatter, bool is_generic_formatter> struct spacer_t : original_formatter {
+ // "fixed" formatter - it has a msg_type typedef
+ typedef typename original_formatter::param param;
+ typedef original_formatter spacer_base;
+ typedef hold_string_type string_type;
+
+ spacer_t(const original_formatter & fmt, const char_type * format_str) : spacer_base(fmt) {
+ parse_format( format_str);
+ }
+
+ void operator()(param msg) const {
+ detail::spacer_write<spacer_base,convert>(msg, *this, m_prefix, m_suffix);
+ }
+private:
+ void parse_format(const string_type & format_str) {
+ typedef typename string_type::size_type size_type;
+ size_type msg_idx = format_str.find('%');
+ if ( msg_idx != string_type::npos) {
+ m_prefix = format_str.substr(0, msg_idx);
+ m_suffix = format_str.substr( msg_idx + 1);
+ }
+ else
+ // no suffix
+ m_prefix = format_str;
+ }
+
+private:
+ string_type m_prefix, m_suffix;
+};
+
+// specialize for generic formatters
+template<class convert, class original_formatter> struct spacer_t<convert,original_formatter,true> : original_formatter {
+ // generic formatter
+ typedef original_formatter spacer_base;
+ typedef hold_string_type string_type;
+
+ spacer_t(const original_formatter & fmt, const char_type * format_str) : spacer_base(fmt) {
+ parse_format( format_str);
+ }
+
+ template<class msg_type> void operator()(msg_type & msg) const {
+ detail::spacer_write<spacer_base,convert>(msg, *this, m_prefix, m_suffix);
+ }
+private:
+ void parse_format(const string_type & format_str) {
+ typedef typename string_type::size_type size_type;
+ size_type msg_idx = format_str.find('%');
+ if ( msg_idx != string_type::npos) {
+ m_prefix = format_str.substr(0, msg_idx);
+ m_suffix = format_str.substr( msg_idx + 1);
+ }
+ else
+ // no suffix
+ m_prefix = format_str;
+ }
+
+private:
+ hold_string_type m_prefix, m_suffix;
+};
+
+
+namespace detail {
+ template<class original_formatter,int> struct find_spacer_generic {
+ // generic
+ typedef typename original_formatter::convert_type convert;
+ typedef spacer_t<convert, original_formatter, true> type;
+ };
+ template<class original_formatter> struct find_spacer_generic<original_formatter,0> {
+ // not generic
+ typedef do_convert_format::prepend convert ;
+ typedef spacer_t<convert, original_formatter, false> type;
+ };
+
+ template<class original_formatter> struct find_spacer : find_spacer_generic<original_formatter, boost::is_base_of<is_generic,original_formatter>::value> {
+ };
+}
+
+/**
+ @copydoc spacer_t
+*/
+template<class original_formatter> typename detail::find_spacer<original_formatter>::type spacer(const original_formatter & fmt, const char_type* format_str) {
+ typedef typename detail::find_spacer<original_formatter>::type spacer_type;
+ return spacer_type(fmt, format_str);
+}
+
+
+}}}
+
+#endif
+

Modified: sandbox/logging/boost/logging/format/formatter/tags.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/formatter/tags.hpp (original)
+++ sandbox/logging/boost/logging/format/formatter/tags.hpp 2007-11-30 05:51:33 EST (Fri, 30 Nov 2007)
@@ -60,6 +60,7 @@
 See @ref boost::logging::tag "how to use tags".
 */
 template<class convert = do_convert_format::prepend> struct file_line_t : is_generic, uses_tag< file_line_t<convert>, ::boost::logging::tag::file_line >, boost::logging::op_equal::always_equal {
+ typedef convert convert_type;
     template<class msg_type, class tag_type> void write_tag(msg_type & str, const tag_type & tag) const {
         convert::write( tag.val, str);
     }
@@ -72,6 +73,7 @@
 See @ref boost::logging::tag "how to use tags".
 */
 template<class convert = do_convert_format::prepend> struct function_t : is_generic, uses_tag< function_t<convert>, ::boost::logging::tag::function >, boost::logging::op_equal::always_equal {
+ typedef convert convert_type;
     template<class msg_type, class tag_type> void write_tag(msg_type & str, const tag_type & tag) const {
         convert::write( tag.val, str);
     }
@@ -84,6 +86,7 @@
 See @ref boost::logging::tag "how to use tags".
 */
 template<class convert = do_convert_format::prepend> struct level_t : is_generic, uses_tag< level_t<convert>, ::boost::logging::tag::level >, boost::logging::op_equal::always_equal {
+ typedef convert convert_type;
     template<class msg_type, class tag_type> void write_tag(msg_type & str, const tag_type & tag) const {
         typedef typename boost::logging::dump_level<>::type dump_type;
         convert::write( dump_type::dump(tag.val) , str);
@@ -99,6 +102,7 @@
 See @ref boost::logging::tag "how to use tags".
 */
 template<class convert = do_convert_format::prepend> struct time_t : is_generic, uses_tag< time_t<convert>, ::boost::logging::tag::time > {
+ typedef convert convert_type;
     typedef boost::logging::formatter::time_t<convert> time_write_type;
     time_write_type m_writer;
 
@@ -122,6 +126,7 @@
 See @ref boost::logging::tag "how to use tags".
 */
 template<class convert = do_convert_format::prepend> struct module_t : is_generic, uses_tag< module_t<convert>, ::boost::logging::tag::module >, boost::logging::op_equal::always_equal {
+ typedef convert convert_type;
     template<class msg_type, class tag_type> void write_tag(msg_type & str, const tag_type & tag) const {
         convert::write( tag.val, str);
     }
@@ -136,9 +141,10 @@
 template<class stream_type = ::std::basic_ostringstream<char_type> , class convert = do_convert_format::prepend> struct thread_id_t
         : is_generic, uses_tag< thread_id_t< ::std::basic_ostringstream<char_type>, convert>, ::boost::logging::tag::thread_id >, boost::logging::op_equal::always_equal {
 
+ typedef convert convert_type;
     template<class msg_type, class tag_type> void write_tag(msg_type & str, const tag_type & tag) const {
         stream_type out;
- out << BOOST_LOG_STR("[T") << tag.val << BOOST_LOG_STR("] ");
+ out << tag.val ;
         convert::write( out.str(), str);
     }
 };

Modified: sandbox/logging/boost/logging/format/formatter/thread_id.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/formatter/thread_id.hpp (original)
+++ sandbox/logging/boost/logging/format/formatter/thread_id.hpp 2007-11-30 05:51:33 EST (Fri, 30 Nov 2007)
@@ -35,9 +35,11 @@
 For instance, you might use @ref boost::logging::optimize::cache_string_one_str "a cached_string class" (see @ref boost::logging::optimize "optimize namespace").
 */
 template<class convert = do_convert_format::prepend> struct thread_id_t : is_generic, boost::logging::op_equal::always_equal {
+ typedef convert convert_type;
+
     template<class msg_type> void operator()(msg_type & msg) const {
         std::basic_ostringstream<char_type> out;
- out << BOOST_LOG_STR("[T")
+ out
     #if defined (BOOST_HAS_WINTHREADS)
             << ::GetCurrentThreadId()
     #elif defined (BOOST_HAS_PTHREADS)
@@ -45,7 +47,7 @@
     #elif defined (BOOST_HAS_MPTASKS)
             << MPCurrentTaskID()
     #endif
- << BOOST_LOG_STR("] ");
+ ;
 
         convert::write( out.str(), msg );
     }

Modified: sandbox/logging/boost/logging/format/formatter/time.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/formatter/time.hpp (original)
+++ sandbox/logging/boost/logging/format/formatter/time.hpp 2007-11-30 05:51:33 EST (Fri, 30 Nov 2007)
@@ -49,6 +49,7 @@
 For instance, you might use @ref boost::logging::optimize::cache_string_one_str "a cached_string class" (see @ref boost::logging::optimize "optimize namespace").
 */
 template<class convert = do_convert_format::prepend> struct time_t : is_generic {
+ typedef convert convert_type;
 private:
 
     struct index_info {
@@ -169,6 +170,7 @@
 For instance, you might use @ref boost::logging::optimize::cache_string_one_str "a cached_string class" (see @ref boost::logging::optimize "optimize namespace").
 */
 template<class convert = do_convert_format::prepend> struct time_strf_t : is_generic {
+ typedef convert convert_type;
 
     /**
         constructs a time_strf object

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-30 05:51:33 EST (Fri, 30 Nov 2007)
@@ -540,6 +540,14 @@
>
                                         </File>
                                         <File
+ RelativePath="..\..\..\..\..\boost\logging\format\formatter\named_spacer.hpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\..\..\boost\logging\format\formatter\spacer.hpp"
+ >
+ </File>
+ <File
                                                 RelativePath="..\..\..\..\..\boost\logging\format\formatter\tags.hpp"
>
                                         </File>

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 2007-11-30 05:51:33 EST (Fri, 30 Nov 2007)
@@ -1,106 +1,98 @@
+/**
+@example one_loger_one_filter.cpp
+
+@copydoc one_loger_one_filter
+
+@page one_loger_one_filter one_loger_one_filter.cpp Example
+
+
+This usage:
+- You have one logger
+- You have 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, debug output window, and a file called out.txt
+ - Formatting - prefix each message by its index, and append newline
+
+Optimizations:
+- use a cache string (from optimize namespace), in order to make formatting the message faster
+
+In this example, all output will be written to the console, debug window, and "out.txt" file.
+It will be:
+
+@code
+[1] this is so cool 1
+[2] this is so cool again 2
+[3] hello, world
+[4] good to be back ;) 3
+@endcode
+
+*/
+
+
 
 #define BOOST_LOG_COMPILE_FAST_OFF
 #include <boost/logging/format_fwd.hpp>
-#include <boost/logging/tags.hpp>
 
 // Step 1: Optimize : use a cache string, to make formatting the message faster
-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; //(1a)
-//typedef bl::tag::holder< bl::hold_string_type, bl::tag::file_line, bl::tag::thread_id, bl::tag::time> log_string; //(1b)
-BOOST_LOG_FORMAT_MSG( log_string )
+BOOST_LOG_FORMAT_MSG( optimize::cache_string_one_str<> )
 
 #include <boost/logging/format.hpp>
+#include <boost/logging/format/formatter/thread_id.hpp>
 #include <boost/logging/writer/ts_write.hpp>
-#include <boost/logging/format/formatter/tags.hpp>
-
-#include <boost/logging/detail/scoped_log.hpp>
-
 
 using namespace boost::logging;
 
 // Step 3 : Specify your logging class(es)
-using namespace boost::logging::scenario::usage;
-typedef use<default_,filter_::level::use_levels> finder;
+typedef logger_format_write< > log_type;
+
 
 // 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_l, finder::logger)
+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() ) .set_tag( BOOST_LOG_TAG_FILELINE)
-#define LDBG BOOST_LOG_USE_LOG_IF_LEVEL(g_l, g_log_filter, debug ) \
- .set_tag( BOOST_LOG_TAG_FILELINE) << "[dbg] "
-#define LINF BOOST_LOG_USE_LOG_IF_LEVEL(g_l, g_log_filter, info ) \
- .set_tag( BOOST_LOG_TAG_FILELINE) << "[inf] "
-#define LWRN BOOST_LOG_USE_LOG_IF_LEVEL(g_l, g_log_filter, warning ) \
- .set_tag( BOOST_LOG_TAG_FILELINE) << "[wrn] "
-#define LERR BOOST_LOG_USE_LOG_IF_LEVEL(g_l, g_log_filter, error ) \
- .set_tag( BOOST_LOG_TAG_FILELINE) << "[err] "
-#define LFAT BOOST_LOG_USE_LOG_IF_LEVEL(g_l, g_log_filter, fatal ) \
- .set_tag( BOOST_LOG_TAG_FILELINE) << "[fat] "
-
-void init_logs();
-
-
-
+#define L_ BOOST_LOG_USE_LOG_IF_FILTER(g_l, 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_l, finder::logger)
-
-void init_logs() {
- using namespace boost::logging;
- // Add formatters and destinations
- // That is, how the message is to be formatted...
- g_l->writer().add_formatter( formatter::tag::time("$hh:$mm.$ss ") );
-// g_l->writer().add_formatter( formatter::tag::file_line() );
- g_l->writer().add_formatter( formatter::idx() );
-// g_l->writer().add_formatter( formatter::append_newline_if_needed() ); //(2a)
- g_l->writer().add_formatter( formatter::append_newline() ); //(2b)
-
- // ... 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::rolling_file("atne_logging",
- destination::rolling_file_settings().max_size_bytes(1024 * 10) )
- );
- */ g_l->writer().add_destination( destination::file("out.txt") );
-}
+BOOST_DEFINE_LOG_FILTER(g_log_filter, filter::no_ts )
+BOOST_DEFINE_LOG(g_l, log_type)
 
 
+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::thread_id(), "{T%}-_ " );
+ g_l->writer().add_formatter( formatter::append_newline_if_needed() );
+ g_l->writer().add_destination( destination::file("out.txt") );
+ g_l->writer().add_destination( destination::cout() );
+ g_l->writer().add_destination( destination::dbg_window() );
 
-void test(int a, const char * str) {
-// BOOST_SCOPED_LOG(LDBG, "testing inout" << a << str );
- std::string s;
- BOOST_SCOPED_LOG(LDBG << , "testing inout" );
-// BOOST_SCOPED_LOG(LDBG << , "testing inout2" );
+ // Step 8: use it...
     int i = 1;
-// LDBG << "this is so cool " << i++ << "\n";
-}
-
+ L_ << "this is so cool " << i++;
+ L_ << "this is so cool again " << i++;
 
-void test2(int a, const char * str) {
- BOOST_SCOPED_LOG_CTX(LDBG) << "test21-" << a << ", str=" << str;
- BOOST_SCOPED_LOG_CTX(LDBG) << "test22-" << a << ", str=" << str;
-}
+ std::string hello = "hello", world = "world";
+ L_ << hello << ", " << world;
 
-void your_scenario_example() {
+ g_log_filter->set_enabled(false);
+ L_ << "this will not be written to the log";
+ L_ << "this won't be written to the log";
 
- init_logs();
+ g_log_filter->set_enabled(true);
+ L_ << "good to be back ;) " << i++;
 
- test(5, "cucu");
- test2(5, "cucu2");
- // Step 8: use it...
- int i = 1;
- LDBG << "the end" << i++ << "\n";
+ // Step 9 : Enjoy!
 }
 
 
 
 
 int main() {
- your_scenario_example();
+ one_logger_one_filter_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