Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2007-11-13 14:55:07


Author: jtorjo
Date: 2007-11-13 14:55:07 EST (Tue, 13 Nov 2007)
New Revision: 41066
URL: http://svn.boost.org/trac/boost/changeset/41066

Log:
[logging]
v0.11.10, 12 nov 2007
- added destination::stream and test_log_output
Added:
   sandbox/logging/lib/logging/tests/test_log_output/
Text files modified:
   sandbox/logging/boost/logging/detail/fwd.hpp | 22 ++++
   sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp | 3
   sandbox/logging/boost/logging/format/destination/defaults.hpp | 44 ++++++++++
   sandbox/logging/boost/logging/format/destination/file.hpp | 4
   sandbox/logging/boost/logging/format/destination/rolling_file.hpp | 4
   sandbox/logging/lib/logging/internal/vc8/loggingvc8/loggingvc8.vcproj | 9 +
   sandbox/logging/lib/logging/tests/do_not_use/testfast.cpp | 170 +++++++++++++++++++++++++++++++++------
   7 files changed, 222 insertions(+), 34 deletions(-)

Modified: sandbox/logging/boost/logging/detail/fwd.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/fwd.hpp (original)
+++ sandbox/logging/boost/logging/detail/fwd.hpp 2007-11-13 14:55:07 EST (Tue, 13 Nov 2007)
@@ -59,14 +59,31 @@
 
 
 
- /**
+ /*
         just in case you're doing a typo - "write" instead of "writer"
     */
     namespace write = writer;
 
 
 
+/**
+@page dealing_with_flags Dealing with flags.
+
+Some classes have extra settings. You can specify these settings in the class'es constructor.
+When setting a certain value, there's a very simple pattern:
+
+@code
+some_object obj(..., some_object_settings().setting1(value1).setting2(value2)....);
+@endcode
+
+Example:
 
+@code
+using namespace destination;
+file f("out.txt", file_settings.initial_overwrite(true).do_append(false) );
+@endcode
+
+*/
 
 
 namespace detail {
@@ -88,6 +105,9 @@
         self_type * m_self;
     };
 
+ /**
+ @brief Can hold a flag. See dealing_with_flags
+ */
     template<class self_type> struct flag {
         template<class val_type> struct t : flag_with_self_type<self_type,val_type> {
             typedef flag_with_self_type<self_type,val_type> flag_base_type;

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-13 14:55:07 EST (Tue, 13 Nov 2007)
@@ -1,7 +1,8 @@
 /**
 @page page_changelog Changelog
 
-_at_section changelog_cur_ver Current Version: v0.11.9, 12 nov 2007
+@section changelog_cur_ver Current Version: v0.11.10, 12 nov 2007
+- added destination::stream and test_log_output
 - applied small patch from Jens Seidel - many thanks!
 - moved a few files into detail/ directory - to avoid confusion as to what header should be included when
 - fixed bug when including only macros.hpp file - many thanks Jens Seidel!

Modified: sandbox/logging/boost/logging/format/destination/defaults.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/destination/defaults.hpp (original)
+++ sandbox/logging/boost/logging/format/destination/defaults.hpp 2007-11-13 14:55:07 EST (Tue, 13 Nov 2007)
@@ -46,6 +46,43 @@
 
 
 /**
+ @brief writes to stream.
+
+ The stream must outlive this object! Or, clear() the stream, before the stream is deleted.
+*/
+template<class convert_dest = do_convert_destination > struct stream_t : is_generic, non_const_context< std::basic_ostream<boost::logging::char_type> * > {
+ typedef std::basic_ostream<char_type> stream_type;
+ typedef non_const_context< stream_type* > non_const_context_base;
+
+ stream_t(stream_type * s) : non_const_context_base(s) {
+ }
+ stream_t(stream_type & s) : non_const_context_base(&s) {
+ }
+
+ template<class msg_type> void operator()(const msg_type & msg) const {
+ if ( non_const_context_base::context() )
+ convert_dest::write(msg, *non_const_context_base::context());
+ }
+
+ bool operator==(const stream_t & other) const {
+ return non_const_context_base::context() != other.non_const_context_base::context();
+ }
+
+ /**
+ @brief resets the stream. Further output will be written to this stream
+ */
+ void stream(stream_type * p) { non_const_context_base::context() = p; }
+
+ /**
+ @brief clears the stream. Further output will be ignored
+ */
+ void clear() { stream(0); }
+};
+
+
+
+
+/**
     @brief Writes the string to output debug window
 
     For non-Windows systems, this is the console.
@@ -66,12 +103,19 @@
     }
 };
 
+
 /** @brief cout_t with default values. See cout_t
 
 @copydoc cout_t
 */
 typedef cout_t<> cout;
 
+/** @brief stream_t with default values. See stream_t
+
+@copydoc stream_t
+*/
+typedef stream_t<> stream;
+
 /** @brief dbg_window_t with default values. See dbg_window_t
 
 @copydoc dbg_window_t

Modified: sandbox/logging/boost/logging/format/destination/file.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/destination/file.hpp (original)
+++ sandbox/logging/boost/logging/format/destination/file.hpp 2007-11-13 14:55:07 EST (Tue, 13 Nov 2007)
@@ -36,7 +36,7 @@
 namespace boost { namespace logging { namespace destination {
 
 /**
- @brief settings for when constructing a file class
+ @brief settings for when constructing a file class. To see how it's used, see @ref dealing_with_flags.
 */
 struct file_settings {
     typedef detail::flag<file_settings> flag;
@@ -91,7 +91,7 @@
         @brief constructs the file destination
 
         @param file_name name of the file
- @param set [optional] file settings - see file_settings class
+ @param set [optional] file settings - see file_settings class, and @ref dealing_with_flags
     */
     file_t(const std::string & file_name, file_settings set = file_settings() ) : non_const_context_base(file_name,set) {}
     template<class msg_type> void operator()(const msg_type & msg) const {

Modified: sandbox/logging/boost/logging/format/destination/rolling_file.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/destination/rolling_file.hpp (original)
+++ sandbox/logging/boost/logging/format/destination/rolling_file.hpp 2007-11-13 14:55:07 EST (Tue, 13 Nov 2007)
@@ -38,7 +38,7 @@
 
 
 /**
- @brief Settings you can pass to the rolling file
+ @brief Settings you can pass to the rolling file. To see how it's used, see @ref dealing_with_flags.
 */
 struct rolling_file_settings {
     typedef boost::logging::detail::flag<rolling_file_settings> flag;
@@ -136,7 +136,7 @@
 
         @param name_prefix the name to be used as prefix for the files
         
- @param flags [optional] extra settings to pass to the rolling file. See rolling_file_settings.
+ @param flags [optional] extra settings to pass to the rolling file. See rolling_file_settings and @ref dealing_with_flags.
     */
     rolling_file_t(const std::string & name_prefix, rolling_file_settings flags = rolling_file_settings() ) : non_const_context_base(name_prefix, flags) {}
 

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-13 14:55:07 EST (Tue, 13 Nov 2007)
@@ -510,7 +510,6 @@
>
                                 <FileConfiguration
                                         Name="Test|Win32"
- ExcludedFromBuild="true"
>
                                         <Tool
                                                 Name="VCCLCompilerTool"
@@ -1032,6 +1031,14 @@
                         <File
                                 RelativePath="..\..\..\samples\scenarios\using_tags.cpp"
>
+ <FileConfiguration
+ Name="Test|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
                         </File>
                         <File
                                 RelativePath="..\..\..\samples\scenarios\your_scenario.cpp"

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-13 14:55:07 EST (Tue, 13 Nov 2007)
@@ -17,51 +17,167 @@
 // See http://www.torjo.com/log2/ for more details
 
 
+/**
+@example your_scenario.cpp
 
-#define BOOST_LOG_COMPILE_FAST_OFF
-#include <boost/logging/format_fwd.hpp>
-#include <boost/logging/tags.hpp>
+@copydoc your_scenario
 
-using namespace boost::logging;
-typedef tag::holder< optimize::cache_string_one_str<>, tag::time, tag::file_line, tag::function> string;
+@page your_scenario your_scenario.cpp Example
 
-// Step 1: Optimize : use a cache string, to make formatting the message faster
-BOOST_LOG_FORMAT_MSG( string )
 
+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
+*/
 
-// Step 3 : Specify your logging class(es)
-typedef logger_format_write< > log_type;
 
-#include <boost/logging/format.hpp>
-#include <boost/logging/writer/ts_write.hpp>
-#include <boost/logging/format/formatter/tags.hpp>
 
+#define BOOST_LOG_COMPILE_FAST_OFF
+#include <boost/logging/format_fwd.hpp>
 
-// 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_DEFINE_LOG_FILTER(g_log_filter, filter::no_ts )
-BOOST_DEFINE_LOG(g_l, log_type)
+// Step 1: Optimize : use a cache string, to make formatting the message faster
+BOOST_LOG_FORMAT_MSG( optimize::cache_string_one_str<> )
 
-#define L_ BOOST_LOG_USE_LOG_IF_FILTER(g_l, g_log_filter->is_enabled() ) .set_tag(BOOST_LOG_TAG_FILELINE ).set_tag(BOOST_LOG_TAG_FUNCTION)
+#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
 
- g_l->writer().add_formatter( formatter::idx() );
-// g_l->writer().add_formatter( formatter::tag::file_line() );
- g_l->writer().add_formatter( formatter::tag::function() );
- 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() );
+ // 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;
- L_ << "this is so cool " << i++;
- L_ << "this is so cool again " << i++;
+ 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);
 }
 
 


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