Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2007-12-28 15:19:56


Author: jtorjo
Date: 2007-12-28 15:19:55 EST (Fri, 28 Dec 2007)
New Revision: 42323
URL: http://svn.boost.org/trac/boost/changeset/42323

Log:
[logging]
v0.12.11, 11 dec 2007
- added possibility to flush a rolling file, and fixed a bug

Text files modified:
   sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp | 3 ++-
   sandbox/logging/boost/logging/detail/raw_doc/todo.hpp | 2 +-
   sandbox/logging/boost/logging/format/destination/rolling_file.hpp | 23 +++++++++++++++++++++++
   3 files changed, 26 insertions(+), 2 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-28 15:19:55 EST (Fri, 28 Dec 2007)
@@ -1,7 +1,8 @@
 /**
 @page page_changelog Changelog
 
-_at_section changelog_cur_ver Current Version: v0.12.10, 7 dec 2007
+@section changelog_cur_ver Current Version: v0.12.11, 11 dec 2007
+- 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!
 - added high precision timer

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-28 15:19:55 EST (Fri, 28 Dec 2007)
@@ -70,7 +70,7 @@
   Such assert would log into log file and invoke system assert depends in assert level. It could be an addon to core functionality. \n
   Note: SMART_ASSERT should be used for this.
 
-
+- @c normal Allow using log from DLL and EXE (on Windows). Same for Linux. This should normally work - just need to explain how.
 
 
 @section todo_formatters Formatters

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-12-28 15:19:55 EST (Fri, 28 Dec 2007)
@@ -48,6 +48,7 @@
         , file_count(this, 10)
         , initial_erase(this, false)
         , start_where_size_not_exceeded(this, true)
+ , flush_each_time(this, false)
     {}
 
     /// maximum size in bytes, by default 1Mb
@@ -59,6 +60,9 @@
     /// if true, it starts with the first file that hasn't exceeded the max size;
     /// 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)
+ flag::t<bool> flush_each_time;
 };
 
 namespace detail {
@@ -102,16 +106,28 @@
         void recreate_file() {
             m_out = boost::shared_ptr< std::basic_ofstream<char_type> >(new std::basic_ofstream<char_type>( file_name(m_cur_idx).c_str(),
                 std::ios_base::out | std::ios_base::app));
+ if ( m_out->tellp() > m_flags.max_size_bytes()) {
+ // this file is already full - clear it first
+ m_out = boost::shared_ptr< std::basic_ofstream<char_type> >(new std::basic_ofstream<char_type>( file_name(m_cur_idx).c_str(),
+ std::ios_base::out | std::ios_base::trunc));
+ }
         }
 
         template<class msg_type> void write( const msg_type& msg) {
             convert_dest::write(msg, (*m_out) );
+ if ( m_flags.flush_each_time())
+ m_out->flush();
+
             if ( m_out->tellp() > m_flags.max_size_bytes()) {
                 m_cur_idx = (m_cur_idx + 1) % m_flags.file_count();
                 recreate_file();
             }
         }
 
+ void flush() {
+ m_out->flush();
+ }
+
         boost::shared_ptr< std::basic_ofstream<char_type> > m_out;
         std::string m_name_prefix;
         rolling_file_settings m_flags;
@@ -147,6 +163,13 @@
     bool operator==(const rolling_file_t & other) const {
         return non_const_context_base::context().m_name_prefix == other.context().m_name_prefix;
     }
+
+ /**
+ manual flush()ing the currently opened file.
+ */
+ void flush() {
+ non_const_context_base::context().flush();
+ }
 };
 
 /** @brief rolling_file_t with default values. See rolling_file_t


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