Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2007-12-06 17:05:31


Author: jtorjo
Date: 2007-12-06 17:05:30 EST (Thu, 06 Dec 2007)
New Revision: 41808
URL: http://svn.boost.org/trac/boost/changeset/41808

Log:
[logging]
- works with std::wstring now

Added:
   sandbox/logging/boost/logging/tag/high_precision_time.hpp (contents, props changed)
Text files modified:
   sandbox/logging/boost/logging/defaults.hpp | 4
   sandbox/logging/boost/logging/detail/raw_doc/todo.hpp | 7 +
   sandbox/logging/boost/logging/tag/defaults.hpp | 2
   sandbox/logging/lib/logging/internal/vc8/loggingvc8/loggingvc8.vcproj | 4 +
   sandbox/logging/lib/logging/internal/vc8/loggingvc8/test_now.cpp | 132 +++++++++++++++++++++++++++------------
   5 files changed, 103 insertions(+), 46 deletions(-)

Modified: sandbox/logging/boost/logging/defaults.hpp
==============================================================================
--- sandbox/logging/boost/logging/defaults.hpp (original)
+++ sandbox/logging/boost/logging/defaults.hpp 2007-12-06 17:05:30 EST (Thu, 06 Dec 2007)
@@ -63,11 +63,11 @@
 
 */
 
-// define this if you want your char type to be 'wchar_t'
-#undef BOOST_LOG_USE_WCHAR_T
+// define BOOST_LOG_USE_WCHAR_T if you want your char type to be 'wchar_t'
 
 #ifdef BOOST_WINDOWS
 #if defined( UNICODE) || defined(_UNICODE)
+#undef BOOST_LOG_USE_WCHAR_T
 #define BOOST_LOG_USE_WCHAR_T
 #endif
 #endif

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-06 17:05:30 EST (Thu, 06 Dec 2007)
@@ -76,8 +76,6 @@
 @section todo_formatters Formatters
 
 
-- @c high new formatter - write a more "exact" time - up to the millisec or so; should use Boost.DateTime for higher-resolution timestamps.
-
 - @c low new formatter: limit the text to gives maximal length. It may happend the dump is unexpectedly large and would
   fill disk/overwrite cache/take too much time/be unreadable. Limiting one log size would help here a lot and would relieve end user of doing it manually.
 
@@ -104,6 +102,11 @@
 - @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
 
 @section todo_docs Documentation
 

Modified: sandbox/logging/boost/logging/tag/defaults.hpp
==============================================================================
--- sandbox/logging/boost/logging/tag/defaults.hpp (original)
+++ sandbox/logging/boost/logging/tag/defaults.hpp 2007-12-06 17:05:30 EST (Thu, 06 Dec 2007)
@@ -64,6 +64,8 @@
 };
 
 
+
+
 /** @brief tag that holds module context information (note: you need to specify the module yourself)
 
 See @ref boost::logging::tag "how to use tags".

Added: sandbox/logging/boost/logging/tag/high_precision_time.hpp
==============================================================================
--- (empty file)
+++ sandbox/logging/boost/logging/tag/high_precision_time.hpp 2007-12-06 17:05:30 EST (Thu, 06 Dec 2007)
@@ -0,0 +1,76 @@
+// high_precision_time.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_high_precision_tag_HPP_DEFINED
+#define JT28092007_high_precision_tag_HPP_DEFINED
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#include <boost/logging/detail/fwd.hpp>
+#include <boost/date_time/posix_time/ptime.hpp>
+#include <boost/date_time/microsec_time_clock.hpp>
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+
+namespace boost { namespace logging {
+
+namespace tag {
+
+
+/** @brief tag that holds the current time (with high precision) context information
+
+See @ref boost::logging::tag "how to use tags".
+*/
+struct high_precision_time {
+ high_precision_time() : val( ::boost::posix_time::microsec_clock::local_time() ) {}
+ ::boost::posix_time::ptime val;
+};
+
+}
+
+namespace formatter { namespace tag {
+
+/** @brief Dumps current high_precision_time information (corresponds to boost::logging::tag::high_precision_time tag class)
+
+Similar to boost::logging::formatter::high_precision_time_t class - only that this one uses tags.
+
+See @ref boost::logging::tag "how to use tags".
+*/
+template<class convert = do_convert_format::prepend> struct high_precision_time_t : is_generic, uses_tag< high_precision_time_t<convert>, ::boost::logging::tag::high_precision_time > {
+ typedef convert convert_type;
+ typedef boost::logging::formatter::high_precision_time_t<convert> high_precision_time_write_type;
+ high_precision_time_write_type m_writer;
+
+ high_precision_time_t(const hold_string_type & format) : m_writer(format) {}
+
+ template<class msg_type, class tag_type> void write_tag(msg_type & str, const tag_type & tag) const {
+ m_writer.write_high_precision_time(str, tag.val);
+ }
+
+ bool operator==(const high_precision_time_t & other) const {
+ return m_writer == other.m_writer ;
+ }
+
+};
+
+
+}}
+
+}}
+
+#endif
+

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-06 17:05:30 EST (Thu, 06 Dec 2007)
@@ -649,6 +649,10 @@
>
                                 </File>
                                 <File
+ RelativePath="..\..\..\..\..\boost\logging\tag\high_precision_time.hpp"
+ >
+ </File>
+ <File
                                         RelativePath="..\..\..\..\..\boost\logging\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-12-06 17:05:30 EST (Thu, 06 Dec 2007)
@@ -1,35 +1,64 @@
 /**
-_at_example one_loger_one_filter.cpp
+@example mul_levels_mul_logers.cpp
 
-_at_copydoc one_loger_one_filter
+@copydoc mul_levels_mul_logers
 
-_at_page one_loger_one_filter one_loger_one_filter.cpp Example
+@page mul_levels_mul_logers mul_levels_mul_logers.cpp Example
 
 
 This usage:
-- You have one logger
-- You have one filter, which can be turned on or off
+- You have multiple levels (in this example: debug < info < error)
 - 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
+ (in this example: prefix it by time, by index and append newline to it)
+- You have several loggers
+- Each logger has several log destinations
 
 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:
+Logs:
+- Error messages go into err.txt file
+ - formatting - prefix each message by time, index, and append newline
+- Info output goes to console, and a file called out.txt
+ - formatting - prefix each message by "[app]", time, and append newline
+- Debug messages go to the debug output window, and a file called out.txt
+ - formatting - prefix each message by "[dbg]", time, and append newline
 
+
+Here's how the output will look like:
+
+The debug output window:
+@code
+07:52.30 [dbg] this is so cool 1
+07:52.30 [dbg] this is so cool again 2
+@endcode
+
+
+The console:
+@code
+07:52.30 [app] hello, world
+07:52.30 [app] good to be back ;) 4
+@endcode
+
+
+The out.txt file:
 @code
-[1] this is so cool 1
-[2] this is so cool again 2
-[3] hello, world
-[4] good to be back ;) 3
+07:52.30 [dbg] this is so cool 1
+07:52.30 [dbg] this is so cool again 2
+07:52.30 [app] hello, world
+07:52.30 [app] good to be back ;) 4
 @endcode
 
+
+The err.txt file
+@code
+07:52.30 [1] first error 3
+07:52.30 [2] second error 5
+@endcode
 */
 
 
+#define BOOST_LOG_USE_WCHAR_T
 
 #include <boost/logging/format_fwd.hpp>
 
@@ -38,50 +67,69 @@
 
 #include <boost/logging/format.hpp>
 #include <boost/logging/writer/ts_write.hpp>
-#include <boost/logging/format/formatter/high_precision_time.hpp>
-
-using namespace boost::logging;
 
 // Step 3 : Specify your logging class(es)
-typedef logger_format_write< > log_type;
+typedef boost::logging::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, filter::no_ts )
-BOOST_DECLARE_LOG(g_l, log_type)
+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)
 
 // 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() )
+#define LDBG_ BOOST_LOG_USE_LOG_IF_LEVEL(g_log_dbg, g_log_level, debug )
+#define LERR_ BOOST_LOG_USE_LOG_IF_LEVEL(g_log_err, g_log_level, error )
+#define LAPP_ BOOST_LOG_USE_LOG_IF_LEVEL(g_log_app, g_log_level, info )
 
 // 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_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)
 
+using namespace boost::logging;
 
-void one_logger_one_filter_example() {
+void mul_levels_mul_logers_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::high_precision_time("$hh:$mm:$ss:$nano ") );
- 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() );
+ // Err log
+ g_log_err->writer().add_formatter( formatter::idx(), L"[%] " );
+ g_log_err->writer().add_formatter( formatter::time( L"$hh:$mm.$ss ") );
+ g_log_err->writer().add_formatter( formatter::append_newline() );
+ g_log_err->writer().add_destination( destination::file("err.txt") );
+
+ destination::file out("out.txt");
+ // App log
+ g_log_app->writer().add_formatter( formatter::time(L"$hh:$mm.$ss ") );
+ g_log_app->writer().add_formatter( formatter::append_newline() );
+ g_log_app->writer().add_destination( out );
+ g_log_app->writer().add_destination( destination::cout() );
+
+ // Debug log
+ g_log_dbg->writer().add_formatter( formatter::time(L"$hh:$mm.$ss ") );
+ g_log_dbg->writer().add_formatter( formatter::append_newline() );
+ g_log_dbg->writer().add_destination( out );
+ g_log_dbg->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++;
+ LDBG_ << L"this is so cool " << i++;
+ LDBG_ << L"this is so cool again " << i++;
+ LERR_ << L"first error " << i++;
+
+ std::wstring hello = L"hello", world = L"world";
+ LAPP_ << hello << L", " << world;
+
+ g_log_level->set_enabled(level::error);
+ LDBG_ << L"this will not be written anywhere";
+ LAPP_ << L"this won't be written anywhere either";
+
+ g_log_level->set_enabled(level::info);
+ LAPP_ << L"good to be back ;) " << i++;
+ LERR_ << L"second error " << i++;
 
     // Step 9 : Enjoy!
 }
@@ -90,7 +138,7 @@
 
 
 int main() {
- one_logger_one_filter_example();
+ mul_levels_mul_logers_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