Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2007-12-29 10:18:56


Author: jtorjo
Date: 2007-12-29 10:18:56 EST (Sat, 29 Dec 2007)
New Revision: 42337
URL: http://svn.boost.org/trac/boost/changeset/42337

Log:
[logging]
v0.12.12, 29 dec 2007
- added destination::named - similar to formatter::named_spacer, but for destinations
Added:
   sandbox/logging/boost/logging/format/destination/named.hpp (contents, props changed)
Text files modified:
   sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp | 3 ++-
   sandbox/logging/boost/logging/detail/raw_doc/todo.hpp | 14 ++++++++------
   sandbox/logging/boost/logging/format/formatter/high_precision_time.hpp | 2 +-
   sandbox/logging/lib/logging/internal/vc8/loggingvc8/loggingvc8.vcproj | 13 ++++++++++++-
   sandbox/logging/lib/logging/internal/vc8/loggingvc8/test_now.cpp | 10 ++++++++--
   sandbox/logging/lib/logging/samples/scenarios/mul_levels_one_logger.cpp | 10 +++++++---
   6 files changed, 38 insertions(+), 14 deletions(-)

Modified: sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp 2007-12-29 10:18:56 EST (Sat, 29 Dec 2007)
@@ -1,7 +1,8 @@
 /**
 @page page_changelog Changelog
 
-_at_section changelog_cur_ver Current Version: v0.12.11, 11 dec 2007
+@section changelog_cur_ver Current Version: v0.12.12, 29 dec 2007
+- added destination::named - similar to formatter::named_spacer, but for destinations
 - added possibility to flush a rolling file, and fixed a bug
 - added high precision_time tag
 - added new includes for files to be able to be compiled standalone - many thanks Jens Seidel!

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-12-29 10:18:56 EST (Sat, 29 Dec 2007)
@@ -101,12 +101,9 @@
 
 - @c normal new destination : to Event log
 
-- @c high destination similar to named_spacer; but much easier. add to the docs as well
- spacer string: every destination is separated by space. Each destination name cannot contain punctuation/spaces ;
- to know which destination is to be called, they're separated by space.
- Also, just to make sure we're as friendly as possible (assuming this will go into a config file, and you want to see all names)
- +name means write to this destination
- -name means don't write to this destination
+- @c normal shared_memory is to use interprocess lib.
+
+
 
 @section todo_docs Documentation
 
@@ -123,6 +120,11 @@
 
 - @c normal Documentation about performance of the library is missing - absolute times, # of dynamic allocations per typical log, etc.
 
+- @c high For formatters/destinations - make it easier to see - not necessary from examples.
+ By looking at the namespace itself, it contains other stuff as well. See if I can use @ ingroup or something
+
+- @c normal Explain about config files - you can use named_spacer,named.
+
 */
 
 }}

Added: sandbox/logging/boost/logging/format/destination/named.hpp
==============================================================================
--- (empty file)
+++ sandbox/logging/boost/logging/format/destination/named.hpp 2007-12-29 10:18:56 EST (Sat, 29 Dec 2007)
@@ -0,0 +1,223 @@
+// destination_named.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_destination_named_HPP_DEFINED
+#define JT28092007_destination_named_HPP_DEFINED
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#if defined(_MSC_VER)
+#pragma warning ( disable : 4355)
+#endif
+
+
+
+#include <boost/logging/detail/fwd.hpp>
+#include <boost/logging/detail/manipulator.hpp>
+#include <boost/logging/format/destination/convert_destination.hpp>
+#include <boost/logging/format/array.hpp> // array
+#include <vector>
+#include <boost/type_traits/is_base_of.hpp>
+#include <sstream>
+
+namespace boost { namespace logging { namespace destination {
+
+
+namespace detail {
+ template<class lock_resource, class destination_base> struct named_context {
+ typedef typename use_default<lock_resource, boost::logging::lock_resource_finder::tss_with_cache<> >::type lock_resource_type;
+ typedef typename use_default<destination_base, base<> >::type destination_base_type;
+ typedef ::boost::logging::array::shared_ptr_holder<destination_base_type, boost::logging::threading::no_mutex > array;
+ typedef hold_string_type string_type;
+
+ struct write_info {
+ array destinations;
+ typedef std::map<string_type, destination_base_type* > coll;
+ coll name_to_destination;
+ string_type format_string;
+
+ typedef std::vector< destination_base_type* > step_array;
+ step_array write_steps;
+ };
+ typedef typename lock_resource_type::template finder<write_info>::type data;
+ data m_data;
+
+ template<class destination_type> void add(const string_type & name, destination_type dest) {
+ // care about if generic or not
+ typedef boost::logging::manipulator::is_generic is_generic;
+ add_impl<destination_type>( name, dest, boost::is_base_of<is_generic,destination_type>() );
+ compute_write_steps();
+ }
+
+ void del(const string_type & name) {
+ {
+ typename data::write info(m_data);
+ destination_base_type * p = info->name_to_destination[name];
+ info->name_to_destination.erase(name);
+ info->destinations.del(p);
+ }
+ compute_write_steps();
+ }
+
+ void format_string(const string_type & str) {
+ { typename data::write info(m_data);
+ info->format_string = str;
+ }
+ compute_write_steps();
+ }
+
+ template<class msg_type> void write(msg_type & msg) const {
+ typename data::read info(m_data);
+ for ( typename write_info::step_array::const_iterator b = info->write_steps.begin(), e = info->write_steps.end(); b != e ; ++b)
+ (**b)(msg);
+ }
+
+ private:
+ // non-generic
+ template<class destination_type> void add_impl(const string_type & name, destination_type dest, const boost::false_type& ) {
+ typename data::write info(m_data);
+ destination_base_type * p = info->destinations.append(dest);
+ info->name_to_destination[name] = p;
+ }
+ // generic manipulator
+ template<class destination_type> void add_impl(const string_type & name, destination_type dest, const boost::true_type& ) {
+ typedef boost::logging::manipulator::detail::generic_holder<destination_type,destination_base_type> holder;
+ add_impl( name, holder(dest), boost::false_type() );
+ }
+
+ // recomputes the write steps - note taht this takes place after each operation
+ // for instance, the user might have first set the string and later added the formatters
+ void compute_write_steps() {
+ typedef typename string_type::size_type size_type;
+
+ typename data::write info(m_data);
+ info->write_steps.clear();
+
+ std::basic_istringstream<char_type> in(info->format_string);
+ string_type word;
+ while ( in >> word) {
+ if ( word[0] == '+')
+ word.erase( word.begin());
+ else if ( word[0] == '-')
+ // ignore this word
+ continue;
+
+ if ( info->name_to_destination.find(word) != info->name_to_destination.end())
+ info->write_steps.push_back( info->name_to_destination.find(word)->second);
+ }
+ }
+
+ };
+
+}
+
+/**
+@brief Allows you to contain multiple destinations, give each such destination a name. Then, at run-time, you can specify a format string which will specify which destinations to be called, and on what order.
+
+This allows you:
+- to hold multiple destinations
+- each destination is given a name, when being added. The name <b>must not</b> contain spaces and must not start with '+'/'-' signs
+- you have a %format string, which contains what destinations to be called, and on which order
+
+The %format string contains destination names, separated by space.
+
+When a message is written to this destination, I parse the format string. When a name is encountered, if there's a destination
+corresponding to this name, I will call it.
+
+Example:
+
+@code
+g_l->writer().add_destination(
+ destination::named("cout out debug")
+ .add( "cout", destination::cout())
+ .add( "debug", destination::dbg_window() )
+ .add( "out", destination::file("out.txt"))
+ );
+@endcode
+
+In the above code, we'll write to 3 destinations, in the following order:
+- first, to the console
+- second, to the out.txt file
+- third, to the debug window
+
+
+
+@section If you deal with config files
+
+As an extra feature:
+- if a name starts with '-' is ignored
+- if a name starts with '+', is included.
+
+This is useful if you want to set this format string in a config file. The good thing is that this way you can easily turn on/off
+certain destinations, while seing all the available destinations as well.
+
+Example: \n <tt>+out_file -debug_window +console</tt> \n
+In the above example, I know that the available destinations are @c out_file, @c debug_window and @c console, but I'm not writing to @c debug_window.
+
+
+@code
+#include <boost/logging/format/destination/named.hpp>
+@endcode
+*/
+template<class lock_resource = default_, class destination_base = default_ > struct named_t : is_generic, non_const_context<detail::named_context<lock_resource,destination_base> > {
+ typedef non_const_context< detail::named_context<lock_resource,destination_base> > non_const_context_base;
+ typedef hold_string_type string_type;
+
+ /**
+ @brief constructs the named destination
+
+ @param named_name name of the named
+ @param set [optional] named settings - see named_settings class, and @ref dealing_with_flags
+ */
+ named_t(const string_type & format_string = string_type() ) {
+ non_const_context_base::context().format_string( format_string);
+ }
+ template<class msg_type> void operator()(const msg_type & msg) const {
+ non_const_context_base::context().write(msg);
+ }
+
+
+ named_t & string(const string_type & str) {
+ non_const_context_base::context().format_string(str);
+ return *this;
+ }
+
+ template<class destination> named_t & add(const string_type & name, destination dest) {
+ non_const_context_base::context().add(name, dest);
+ return *this;
+ }
+
+
+ bool operator==(const named_t & other) const {
+ return &( non_const_context_base::context()) == &( other.non_const_context_base::context());
+ }
+};
+
+/** @brief named_t with default values. See named_t
+
+@copydoc named_t
+*/
+typedef named_t<> named;
+
+
+
+
+}}}
+
+#endif
+

Modified: sandbox/logging/boost/logging/format/formatter/high_precision_time.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/formatter/high_precision_time.hpp (original)
+++ sandbox/logging/boost/logging/format/formatter/high_precision_time.hpp 2007-12-29 10:18:56 EST (Sat, 29 Dec 2007)
@@ -77,7 +77,7 @@
     template<class msg_type> void write_high_precision_time(msg_type & msg, ::boost::posix_time::ptime val) const {
         char_type buffer[64];
 
- int nanosecs = val.time_of_day().fractional_seconds();
+ int nanosecs = (int)val.time_of_day().fractional_seconds();
         int digits = val.time_of_day().num_fractional_digits();
         switch ( digits) {
         case 0: break; // no high precision at all

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-12-29 10:18:56 EST (Sat, 29 Dec 2007)
@@ -328,6 +328,14 @@
                         <File
                                 RelativePath=".\test_now.cpp"
>
+ <FileConfiguration
+ Name="Test|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
                         </File>
                 </Filter>
                 <Filter
@@ -592,6 +600,10 @@
>
                                         </File>
                                         <File
+ RelativePath="..\..\..\..\..\boost\logging\format\destination\named.hpp"
+ >
+ </File>
+ <File
                                                 RelativePath="..\..\..\..\..\boost\logging\format\destination\rolling_file.hpp"
>
                                         </File>
@@ -822,7 +834,6 @@
>
                                 <FileConfiguration
                                         Name="Test|Win32"
- ExcludedFromBuild="true"
>
                                         <Tool
                                                 Name="VCCLCompilerTool"

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-12-29 10:18:56 EST (Sat, 29 Dec 2007)
@@ -41,6 +41,7 @@
 #include <boost/logging/format_ts.hpp>
 #include <boost/logging/format/formatter/tags.hpp>
 #include <boost/logging/format/formatter/named_spacer.hpp>
+#include <boost/logging/format/destination/named.hpp>
 
 using namespace boost::logging;
 
@@ -79,8 +80,13 @@
         .add( "fileline", formatter::tag::file_line() ) ); // file/line tag
 
     g_l->writer().add_formatter( formatter::append_newline() );
- g_l->writer().add_destination( destination::cout() );
- g_l->writer().add_destination( destination::file("out.txt") );
+
+ g_l->writer().add_destination(
+ destination::named("+cout out -debug")
+ .add( "cout", destination::cout())
+ .add( "debug", destination::dbg_window() )
+ .add( "out", destination::file("out.txt"))
+ );
 
     // Step 8: use it...
     int i = 1;

Modified: sandbox/logging/lib/logging/samples/scenarios/mul_levels_one_logger.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/mul_levels_one_logger.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/mul_levels_one_logger.cpp 2007-12-29 10:18:56 EST (Sat, 29 Dec 2007)
@@ -31,6 +31,7 @@
 #include <boost/logging/format.hpp>
 #include <boost/logging/writer/ts_write.hpp>
 #include <boost/logging/format/formatter/high_precision_time.hpp>
+#include <boost/logging/format/destination/named.hpp>
 
 using namespace boost::logging;
 // Step 3 : Specify your logging class(es)
@@ -58,9 +59,12 @@
     g_l->writer().add_formatter( formatter::append_newline() );
 
     // ... and where should it be written to
- g_l->writer().add_destination( destination::cout() );
- g_l->writer().add_destination( destination::dbg_window() );
- g_l->writer().add_destination( destination::file("out.txt") );
+ g_l->writer().add_destination(
+ destination::named("cout debug out")
+ .add( "cout", destination::cout())
+ .add( "out", destination::file("out.txt"))
+ .add( "debug", destination::dbg_window() )
+ );
 
     // Step 8: use it...
     int i = 1;


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