Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2008-03-18 18:44:02


Author: jtorjo
Date: 2008-03-18 18:44:01 EDT (Tue, 18 Mar 2008)
New Revision: 43712
URL: http://svn.boost.org/trac/boost/changeset/43712

Log:
v0.23.2, 18 march 2008
- destination::rolling_file - by default, flush after each write
- destination::file - file is created only if logging to it
  (this way, if using named_writer, you won't see spurious files called out.txt, even if not using them)
- destination::rolling_file - file is created only if logging to it
Properties modified:
   sandbox/logging/libs/logging/internal/vc8/loggingvc8/ (props changed)
Text files modified:
   sandbox/logging/boost/logging/detail/fwd.hpp | 2
   sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp | 6 +
   sandbox/logging/boost/logging/detail/raw_doc/main.hpp | 11 ++
   sandbox/logging/boost/logging/detail/raw_doc/table_of_contents.hpp | 1
   sandbox/logging/boost/logging/format/destination/file.hpp | 13 ++
   sandbox/logging/boost/logging/format/destination/rolling_file.hpp | 17 ++-
   sandbox/logging/libs/logging/internal/vc8/loggingvc8/loggingvc8.vcproj | 2
   sandbox/logging/libs/logging/internal/vc8/loggingvc8/test_now.cpp | 196 ++++++++++++++++++++++++++-------------
   8 files changed, 173 insertions(+), 75 deletions(-)

Modified: sandbox/logging/boost/logging/detail/fwd.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/fwd.hpp (original)
+++ sandbox/logging/boost/logging/detail/fwd.hpp 2008-03-18 18:44:01 EDT (Tue, 18 Mar 2008)
@@ -83,7 +83,7 @@
 
 @code
 using namespace destination;
-file f("out.txt", file_settings.initial_overwrite(true).do_append(false) );
+file f("out.txt", file_settings().initial_overwrite(true).do_append(false) );
 @endcode
 
 */

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 2008-03-18 18:44:01 EDT (Tue, 18 Mar 2008)
@@ -1,7 +1,11 @@
 /**
 @page page_changelog Changelog
 
-_at_section changelog_cur_ver Current Version: v0.23.1, 9 march 2008
+@section changelog_cur_ver Current Version: v0.23.2, 18 march 2008
+- destination::rolling_file - by default, flush after each write
+- destination::file - file is created only if logging to it
+ (this way, if using named_writer, you won't see spurious files called out.txt, even if not using them)
+- destination::rolling_file - file is created only if logging to it
 - solved bug: formatter::syslog derived from an undefined class
 
 

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 2008-03-18 18:44:01 EDT (Tue, 18 Mar 2008)
@@ -76,6 +76,17 @@
 
 
 \n\n\n
+@section last_v2 Last version of v2.
+
+The Boost Logging Lib v2 was rejected on 17th of March 2008. I will be working on v3.
+So, you can consider v0.23.2 as the last version of v2. From now on,
+- I will be doing only small fixes, if any major bugs, I'll fix them
+- I will be working on v3. It might take a while until first version of v3 appears - I assume End of April
+- to stay tuned on development, and to make sure your oppinion counts, please check out http://torjo.blogspot.com
+
+
+
+\n\n\n
 @section main_changelog Changelog
 
 @ref page_changelog "See the changelog".

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 2008-03-18 18:44:01 EDT (Tue, 18 Mar 2008)
@@ -10,6 +10,7 @@
 
 - @ref main_intro
     - @ref main_motivation
+ - @ref last_v2
     - @ref main_feeback
     - @ref page_changelog
         - @ref changelog_cur_ver

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 2008-03-18 18:44:01 EDT (Tue, 18 Mar 2008)
@@ -73,13 +73,21 @@
     struct file_info {
         file_info(const std::string& name, file_settings settings)
             : name(name),
- out( new std::basic_ofstream<char_type>( name.c_str(), open_flags(settings) )),
               settings(settings) {}
 
         void reopen() {
             out = boost::shared_ptr< std::basic_ofstream<char_type> > ( new std::basic_ofstream<char_type>( name.c_str(), open_flags(settings) ) );
         }
 
+ void close() {
+ out = boost::shared_ptr< std::basic_ofstream<char_type> > ( );
+ }
+
+ void open_if_needed() {
+ if ( !out)
+ reopen();
+ }
+
         std::string name;
         boost::shared_ptr< std::basic_ofstream<char_type> > out;
         file_settings settings;
@@ -100,6 +108,7 @@
     */
     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 {
+ non_const_context_base::context().open_if_needed();
         convert_dest::write(msg, *( non_const_context_base::context().out) );
         if ( non_const_context_base::context().settings.flush_each_time() )
             non_const_context_base::context().out->flush();
@@ -115,7 +124,7 @@
     void configure(const hold_string_type & str) {
         // configure - the file name, for now
         non_const_context_base::context().name.assign( str.begin(), str.end() );
- non_const_context_base::context().reopen();
+ non_const_context_base::context().close();
     }
 };
 

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 2008-03-18 18:44:01 EDT (Tue, 18 Mar 2008)
@@ -48,7 +48,7 @@
         , file_count(this, 10)
         , initial_erase(this, false)
         , start_where_size_not_exceeded(this, true)
- , flush_each_time(this, false)
+ , flush_each_time(this, true)
         , extra_flags(this, std::ios_base::out)
     {}
 
@@ -62,7 +62,7 @@
     /// otherwise, it starts with the first file (default = true)
     flag::t<bool> start_where_size_not_exceeded;
 
- /// if true, always flush after write (by default, false)
+ /// if true, always flush after write (by default, true)
     flag::t<bool> flush_each_time;
 
     /// just in case you have some extra flags to pass, when opening each file
@@ -110,8 +110,8 @@
                     // all files are too full (we'll overwrite the first one)
                     m_cur_idx = 0;
             }
-
- recreate_file();
+ // force reopen, even if already open
+ m_out = boost::shared_ptr< std::basic_ofstream<char_type> >();
         }
 
         std::string file_name(int idx) {
@@ -135,7 +135,13 @@
             }
         }
 
+ void create_if_needed() {
+ if ( !m_out)
+ recreate_file();
+ }
+
         template<class msg_type> void write( const msg_type& msg) {
+ create_if_needed();
             convert_dest::write(msg, (*m_out) );
             if ( m_flags.flush_each_time())
                 m_out->flush();
@@ -147,7 +153,8 @@
         }
 
         void flush() {
- m_out->flush();
+ if ( m_out)
+ m_out->flush();
         }
 
         boost::shared_ptr< std::basic_ofstream<char_type> > m_out;

Modified: sandbox/logging/libs/logging/internal/vc8/loggingvc8/loggingvc8.vcproj
==============================================================================
--- sandbox/logging/libs/logging/internal/vc8/loggingvc8/loggingvc8.vcproj (original)
+++ sandbox/logging/libs/logging/internal/vc8/loggingvc8/loggingvc8.vcproj 2008-03-18 18:44:01 EDT (Tue, 18 Mar 2008)
@@ -722,7 +722,7 @@
>
                         </File>
                         <File
- RelativePath="..\..\..\..\..\..\..\..\uk\logging_internal\readme.txt"
+ RelativePath="..\..\..\..\..\..\..\..\uk\ideas\logging_internal\readme.txt"
>
                         </File>
                 </Filter>

Modified: sandbox/logging/libs/logging/internal/vc8/loggingvc8/test_now.cpp
==============================================================================
--- sandbox/logging/libs/logging/internal/vc8/loggingvc8/test_now.cpp (original)
+++ sandbox/logging/libs/logging/internal/vc8/loggingvc8/test_now.cpp 2008-03-18 18:44:01 EDT (Tue, 18 Mar 2008)
@@ -1,74 +1,140 @@
-#ifndef my_app_LOG_H_header
-#define my_app_LOG_H_header
+/**
+ Boost Logging library
 
-#include "boost/logging/logging.hpp"
-#include "boost/logging/format_fwd.hpp"
+ Author: John Torjo, www.torjo.com
 
-namespace bl = boost::logging;
+ Copyright (C) 2007 John Torjo (see www.torjo.com for email)
 
-typedef bl::tag::holder< bl::optimize::cache_string_one_str<>
- , bl::tag::time
- , bl::tag::thread_id
- , bl::tag::level
- //, bl::tag::file_line
- //, bl::tag::function
- > logstring;
-BOOST_LOG_FORMAT_MSG( logstring )
-
-typedef bl::logger_format_write< > my_logger_type;
-typedef bl::level::holder my_filter_type;
-
-BOOST_DECLARE_LOG_FILTER(g_l_level, my_filter_type)
-BOOST_DECLARE_LOG(g_l, my_logger_type)
-
-#define L_(lvl) BOOST_LOG_USE_LOG_IF_LEVEL(g_l(), g_l_level(), lvl ).set_tag( BOOST_LOG_TAG_LEVEL(lvl) )
-// for "context information" which cannot be calc'd automatically (such as time), set_tag must be called
-#define LDBG_ L_ (debug)
-#define LAPP_ L_ (info )
-#define LERR_ L_ (error)
-
-void init_logs();
-
-#endif
-//#include "my_app_log.h"
-
-#include <boost/logging/format.hpp>
-#include <boost/logging/format/formatter/tags.hpp>
-#include <boost/logging/format/formatter/named_spacer.hpp>
+ 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
+*/
+
+/**
+@example mul_levels_mul_logers.cpp
+
+@copydoc mul_levels_mul_logers
+
+@page mul_levels_mul_logers mul_levels_mul_logers.cpp Example
+
+
+This usage:
+- you have multiple levels (in this example: debug < info < error)
+- 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
+
+Optimizations:
+- use a cache string (from boost::logging::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
+
+
+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
+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
+*/
+
+
+
+#include <boost/logging/format/named_write.hpp>
+typedef boost::logging::named_logger<>::type logger_type;
+
+#define LDBG_ BOOST_LOG_USE_LOG_IF_LEVEL(g_log_dbg(), g_log_level(), debug ) << "[dbg] "
+#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 ) << "[app] "
+
+BOOST_DEFINE_LOG_FILTER(g_log_level, boost::logging::level::holder )
+BOOST_DEFINE_LOG(g_log_err, logger_type)
+BOOST_DEFINE_LOG(g_log_app, logger_type)
+BOOST_DEFINE_LOG(g_log_dbg, logger_type)
 
 using namespace boost::logging;
 
-BOOST_DEFINE_LOG_FILTER(g_l_level, my_filter_type )
-BOOST_DEFINE_LOG(g_l, my_logger_type)
+void mul_levels_mul_logers_example() {
+ // reuse the same destination for 2 logs
+ destination::file out("out.txt");
+ g_log_app()->writer().replace_destination("file", out);
+ g_log_dbg()->writer().replace_destination("file", out);
+ // formatting (first param) and destinations (second param)
+ g_log_err()->writer().write("[%idx%] %time%($hh:$mm.$ss) |\n", "cout file(err.txt)"); // line A
+ g_log_app()->writer().write("%time%($hh:$mm.$ss) |\n", "file cout");
+ g_log_dbg()->writer().write("%time%($hh:$mm.$ss) |\n", "file cout debug rol_file(rol.txt)");
+
+ /*
+ Note : the "line A" above originally was:
+ g_log_err()->writer().write("[%idx%] %time%($hh:$mm.$ss) |\n", "file(err.txt)");
+
+ This caused a very strange assertion failure on Fedora8, when the program exits, while destroying the global variables.
+ I've spent some time debugging it but to no avail. I will certainly look more into this.
+ */
+
+ g_log_app()->mark_as_initialized();
+ g_log_err()->mark_as_initialized();
+ g_log_dbg()->mark_as_initialized();
+
+
+ int i = 1;
+ 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_level()->set_enabled(level::error);
+ LDBG_ << "this will not be written anywhere";
+ LAPP_ << "this won't be written anywhere either";
+
+ g_log_level()->set_enabled(level::info);
+ LAPP_ << "good to be back ;) " << i++;
+ LERR_ << "second error " << i++;
+}
+
+
 
-//void init_logs() {
-// // works for Named Formatters and Destinations
-// // see <boost/logging/format/named_write.hpp>
-// // formatting : time [idx] message \n
-// // destinations : console, file "out.txt" and debug window
-// g_l()->writer().write("%time%($hh:$mm.$ss.$mili) [%idx%] |\n", "cout file(out.txt) debug");
-// g_l()->mark_as_initialized();
-// g_l()->turn_cache_off();
-//}
-
-void init_logs() {
- // Add formatters and destinations
- // That is, how the message is to be formatted...
- g_l()->writer().add_formatter( formatter::named_spacer( "%time% [T%thread_id%] %level% :" )
- // (the list of formatters must correspond to the list of tags in the logstring (bl::tag::holder)
- .add("time", formatter::tag::time("$hh:$mm.$ss.$mili ") )
- .add("thread_id", formatter::tag::thread_id() )
- .add("level", formatter::tag::level() )
-// .add("file_line", formatter::tag::file_line() )
-// .add("function", formatter::tag::function() )
- );
- 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()->mark_as_initialized();
 
- BOOST_SCOPED_LOG_CTX(LDBG_) << "a";
+int main() {
+ mul_levels_mul_logers_example();
 }
+
+
+// End of file
+


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