Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2007-12-07 07:57:55


Author: jtorjo
Date: 2007-12-07 07:57:53 EST (Fri, 07 Dec 2007)
New Revision: 41824
URL: http://svn.boost.org/trac/boost/changeset/41824

Log:
[logging]
v0.12.10, 7 dec 2007
- added high precision_time tag
- added new includes for files to be able to be compiled standalone - many thanks Jens Seidel!
Text files modified:
   sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp | 4
   sandbox/logging/boost/logging/detail/raw_doc/main.hpp | 1
   sandbox/logging/boost/logging/detail/raw_doc/miscelaneous.hpp | 8 ++
   sandbox/logging/boost/logging/detail/raw_doc/table_of_contents.hpp | 1
   sandbox/logging/boost/logging/detail/raw_doc/todo.hpp | 2
   sandbox/logging/boost/logging/detail/time_format_holder.hpp | 3
   sandbox/logging/boost/logging/format/formatter/named_spacer.hpp | 2
   sandbox/logging/boost/logging/format/formatter/spacer.hpp | 1
   sandbox/logging/boost/logging/tag/high_precision_time.hpp | 20 +++++
   sandbox/logging/lib/logging/internal/vc8/loggingvc8/test_now.cpp | 145 +++++++++++++--------------------------
   10 files changed, 88 insertions(+), 99 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-07 07:57:53 EST (Fri, 07 Dec 2007)
@@ -1,7 +1,9 @@
 /**
 @page page_changelog Changelog
 
-_at_section changelog_cur_ver Current Version: v0.12.9, 1 dec 2007
+@section changelog_cur_ver Current Version: v0.12.10, 7 dec 2007
+- added high precision_time tag
+- added new includes for files to be able to be compiled standalone - many thanks Jens Seidel!
 - added high precision timer
 - removed "#define BOOST_LOG_COMPILE_FAST_OFF" from samples - no needed and could be misleading
 - added boost::logging::formatter::named_spacer

Modified: sandbox/logging/boost/logging/detail/raw_doc/main.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/main.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/main.hpp 2007-12-07 07:57:53 EST (Fri, 07 Dec 2007)
@@ -26,6 +26,7 @@
     - concepts are also easily separated into namespaces
 - A very flexible interface
 - You don't pay for what you don't use.
+- Allows for internationalization (i18n) - can be used with Unicode characters
 - Fits a lot of @ref common_scenarios "scenarios": from @ref common_scenarios_6 "very simple" (dumping all to one log)
   to @ref scenario::usage "very complex" (multiple logs, some enabled/some not, levels, etc).
 - Allows you to choose how you use logs in your code (by defining your own LOG_ macros, suiting your application)

Modified: sandbox/logging/boost/logging/detail/raw_doc/miscelaneous.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/miscelaneous.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/miscelaneous.hpp 2007-12-07 07:57:53 EST (Fri, 07 Dec 2007)
@@ -14,6 +14,14 @@
 typedef logger_format_write< default_, default_, writer::threading::on_dedicated_thread > log_type;
 @endcode
 
+@section misc_unicode Internationalization - Using Unicode charaters
+
+In case you want to log unicode characters, it's very easy:
+
+- just <tt>\#define BOOST_LOG_USE_WCHAR_T</tt> before including any Boost.Logging files
+- For Windows, in case the @c UNICODE or @c _UNICODE is defined, the @c BOOST_LOG_USE_WCHAR_T is defined automatically for you
+
+
 
 */
 

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-12-07 07:57:53 EST (Fri, 07 Dec 2007)
@@ -35,6 +35,7 @@
 - @ref scoped_logs
 - @ref tag "Using tags"
 - @ref thread_safety
+- @ref misc_unicode
 - @ref macros
     - @ref macros_if_else_strategy
     - @ref macros_using

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-07 07:57:53 EST (Fri, 07 Dec 2007)
@@ -123,8 +123,6 @@
 
 - @c normal Documentation about performance of the library is missing - absolute times, # of dynamic allocations per typical log, etc.
 
-- @c high explain that we can have unicode strings - easily
-
 */
 
 }}

Modified: sandbox/logging/boost/logging/detail/time_format_holder.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/time_format_holder.hpp (original)
+++ sandbox/logging/boost/logging/detail/time_format_holder.hpp 2007-12-07 07:57:53 EST (Fri, 07 Dec 2007)
@@ -23,8 +23,9 @@
 
 #include <boost/logging/detail/fwd.hpp>
 #include <algorithm>
-#include <stdio.h>
+#include <cstdio>
 #include <vector>
+#include <sstream>
 
 namespace boost { namespace logging { namespace detail {
 

Modified: sandbox/logging/boost/logging/format/formatter/named_spacer.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/formatter/named_spacer.hpp (original)
+++ sandbox/logging/boost/logging/format/formatter/named_spacer.hpp 2007-12-07 07:57:53 EST (Fri, 07 Dec 2007)
@@ -26,6 +26,8 @@
 #include <boost/type_traits/is_same.hpp>
 #include <boost/static_assert.hpp>
 #include <boost/logging/detail/manipulator.hpp>
+#include <boost/logging/format/formatter/convert_format.hpp> // do_convert_format
+#include <boost/logging/format/array.hpp> // array
 
 namespace boost { namespace logging { namespace formatter {
 

Modified: sandbox/logging/boost/logging/format/formatter/spacer.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/formatter/spacer.hpp (original)
+++ sandbox/logging/boost/logging/format/formatter/spacer.hpp 2007-12-07 07:57:53 EST (Fri, 07 Dec 2007)
@@ -24,6 +24,7 @@
 #include <boost/logging/detail/fwd.hpp>
 #include <boost/type_traits/is_base_of.hpp>
 #include <boost/logging/format/formatter/convert_format.hpp>
+#include <boost/logging/detail/manipulator.hpp> // is_generic
 
 namespace boost { namespace logging { namespace formatter {
 

Modified: sandbox/logging/boost/logging/tag/high_precision_time.hpp
==============================================================================
--- sandbox/logging/boost/logging/tag/high_precision_time.hpp (original)
+++ sandbox/logging/boost/logging/tag/high_precision_time.hpp 2007-12-07 07:57:53 EST (Fri, 07 Dec 2007)
@@ -26,6 +26,12 @@
 #include <boost/date_time/microsec_time_clock.hpp>
 #include <boost/date_time/posix_time/posix_time_types.hpp>
 
+#include <boost/logging/detail/manipulator.hpp> // is_generic
+#include <boost/logging/format/formatter/tags.hpp> // uses_tag
+#include <boost/logging/format/formatter/high_precision_time.hpp> // high_precision_time_t
+#include <boost/logging/format/formatter/convert_format.hpp> // do_convert_format
+
+
 namespace boost { namespace logging {
 
 namespace tag {
@@ -33,6 +39,10 @@
 
 /** @brief tag that holds the current time (with high precision) context information
 
+@code
+#include <boost/logging/tag/high_precision_time.hpp>
+@endcode
+
 See @ref boost::logging::tag "how to use tags".
 */
 struct high_precision_time {
@@ -46,6 +56,10 @@
 
 /** @brief Dumps current high_precision_time information (corresponds to boost::logging::tag::high_precision_time tag class)
 
+@code
+#include <boost/logging/tag/high_precision_time.hpp>
+@endcode
+
 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".
@@ -67,6 +81,12 @@
 
 };
 
+/** @brief high_precision_time_t with default values. See high_precision_time_t
+
+@copydoc high_precision_time_t
+*/
+typedef high_precision_time_t<> high_precision_time;
+
 
 }}
 

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-07 07:57:53 EST (Fri, 07 Dec 2007)
@@ -1,136 +1,91 @@
 /**
-_at_example mul_levels_mul_logers.cpp
+@example using_tags.cpp
 
-_at_copydoc mul_levels_mul_logers
+@copydoc using_tags
 
-_at_page mul_levels_mul_logers mul_levels_mul_logers.cpp Example
+@page using_tags using_tags.cpp Example
 
 
 This usage:
-- You have multiple levels (in this example: debug < info < error)
+- You have one logger and one filter, which can be turned on or off
 - You want to format the message before it's written
- (in this example: prefix it by time, by index and append newline to it)
-- You have several loggers
-- Each logger has several log destinations
+- The logger has several log destinations
+ - The output goes to console, and a file called out.txt
+ - Formatting - message will look like this: <tt>[file/line] [thread_id] [idx] [time] message [enter] </tt>
 
 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 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
+In this example, all output will be written to the console, debug window, and "out.txt" file.
+The output can look like:
 
-
-Here's how the output will look like:
-
-The debug output window:
-_at_code
-07:52.30 [dbg] this is so cool 1
-07:52.30 [dbg] this is so cool again 2
-_at_endcode
-
-
-The console:
-_at_code
-07:52.30 [app] hello, world
-07:52.30 [app] good to be back ;) 4
-_at_endcode
-
-
-The out.txt file:
 @code
-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
+logging\samples\scenarios\using_tags.cpp:94 [T7204] [1] 14:55 this is so cool 1
+logging\samples\scenarios\using_tags.cpp:95 [T7204] [2] 14:55 this is so cool again 2
 @endcode
 
-
-The err.txt file
-_at_code
-07:52.30 [1] first error 3
-07:52.30 [2] second error 5
-_at_endcode
 */
 
 
-#define BOOST_LOG_USE_WCHAR_T
 
 #include <boost/logging/format_fwd.hpp>
+#include <boost/logging/tags.hpp>
+#include <boost/logging/tag/high_precision_time.hpp>
 
 // Step 1: Optimize : use a cache string, to make formatting the message faster
-BOOST_LOG_FORMAT_MSG( optimize::cache_string_one_str<> )
+namespace bl = boost::logging;
+typedef bl::tag::holder< bl::optimize::cache_string_one_str<>, bl::tag::file_line, bl::tag::thread_id, bl::tag::high_precision_time> log_string;
+BOOST_LOG_FORMAT_MSG( log_string )
 
-#include <boost/logging/format.hpp>
-#include <boost/logging/writer/ts_write.hpp>
 
-// Step 3 : Specify your logging class(es)
-typedef boost::logging::logger_format_write< > log_type;
+#include <boost/logging/format_ts.hpp>
+#include <boost/logging/format/formatter/tags.hpp>
+#include <boost/logging/format/formatter/named_spacer.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::correctness> finder;
 
 // Step 4: declare which filters and loggers you'll use (usually in a header file)
-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)
+BOOST_DECLARE_LOG_FILTER(g_log_filter, finder::filter )
+BOOST_DECLARE_LOG(g_l, finder::logger)
 
 // Step 5: define the macros through which you'll log
-#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 )
+#define L_ BOOST_LOG_USE_LOG_IF_FILTER(g_l, g_log_filter->is_enabled() ) .set_tag( BOOST_LOG_TAG_FILELINE)
 
 // Step 6: Define the filters and loggers you'll use (usually in a source file)
-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)
+BOOST_DEFINE_LOG_FILTER(g_log_filter, finder::filter )
+BOOST_DEFINE_LOG(g_l, finder::logger)
 
-using namespace boost::logging;
 
-void mul_levels_mul_logers_example() {
+void using_tags_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(), 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() );
+ g_l->writer().add_formatter( formatter::named_spacer( "%fileline% [T%thread_id%] [%idx%] %time%" )
+ .add( "time", formatter::tag::high_precision_time("$hh:$mm:$ss.$mili ") ) // time tag
+ .add( "idx", formatter::idx() )
+ .add( "thread_id", formatter::tag::thread_id() ) // thread_id tag
+ .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") );
 
     // Step 8: use it...
     int i = 1;
- 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++;
-
+ L_ << "this is so cool " << i++;
+ L_ << "this is so cool again " << i++;
     // Step 9 : Enjoy!
 }
 
@@ -138,7 +93,7 @@
 
 
 int main() {
- mul_levels_mul_logers_example();
+ using_tags_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