Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2007-12-01 06:12:10


Author: jtorjo
Date: 2007-12-01 06:12:07 EST (Sat, 01 Dec 2007)
New Revision: 41527
URL: http://svn.boost.org/trac/boost/changeset/41527

Log:
[logging]
v0.12.8, 1 dec 2007
- added high precision timer - does not work correctly yet
- bug: the named_spacer does not compile in gcc 4.1 - TO FIX
Added:
   sandbox/logging/boost/logging/detail/time_format_holder.hpp (contents, props changed)
   sandbox/logging/boost/logging/format/formatter/high_precision_time.hpp (contents, props changed)
   sandbox/logging/boost/logging/format/formatter/time_strf.hpp (contents, props changed)
Text files modified:
   sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp | 4
   sandbox/logging/boost/logging/format/formatter/defaults.hpp | 1
   sandbox/logging/boost/logging/format/formatter/named_spacer.hpp | 4 +
   sandbox/logging/boost/logging/format/formatter/time.hpp | 141 +--------------------------------------
   sandbox/logging/lib/logging/internal/vc8/loggingvc8/loggingvc8.vcproj | 23 +++--
   sandbox/logging/lib/logging/internal/vc8/loggingvc8/test_now.cpp | 13 ---
   sandbox/logging/lib/logging/samples/scenarios/custom_fmt_dest.cpp | 1
   sandbox/logging/lib/logging/samples/scenarios/ded_loger_one_filter.cpp | 1
   sandbox/logging/lib/logging/samples/scenarios/mul_levels_mul_logers.cpp | 1
   sandbox/logging/lib/logging/samples/scenarios/mul_levels_one_logger.cpp | 1
   sandbox/logging/lib/logging/samples/scenarios/mul_loggers_one_filter.cpp | 1
   sandbox/logging/lib/logging/samples/scenarios/no_levels_with_route.cpp | 1
   sandbox/logging/lib/logging/samples/scenarios/one_loger_one_filter.cpp | 1
   sandbox/logging/lib/logging/samples/scenarios/ts_loger_one_filter.cpp | 1
   sandbox/logging/lib/logging/samples/scenarios/using_tags.cpp | 1
   sandbox/logging/lib/logging/samples/scenarios/your_scenario.cpp | 1
   16 files changed, 31 insertions(+), 165 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-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -1,7 +1,9 @@
 /**
 @page page_changelog Changelog
 
-_at_section changelog_cur_ver Current Version: v0.12.7, 30 nov 2007
+@section changelog_cur_ver Current Version: v0.12.8, 1 dec 2007
+- added high precision timer - does not work correctly yet
+- removed "#define BOOST_LOG_COMPILE_FAST_OFF" from samples - no needed and could be misleading
 - added boost::logging::formatter::named_spacer
 - created lock_resource_finder namespace - with existing resource lockers
 - added boost::logging::formatter::spacer

Added: sandbox/logging/boost/logging/detail/time_format_holder.hpp
==============================================================================
--- (empty file)
+++ sandbox/logging/boost/logging/detail/time_format_holder.hpp 2007-12-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -0,0 +1,167 @@
+// Template.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_TEMPLATE_HPP_DEFINED
+#define JT28092007_TEMPLATE_HPP_DEFINED
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#include <boost/logging/detail/fwd.hpp>
+#include <algorithm>
+#include <stdio.h>
+#include <vector>
+
+namespace boost { namespace logging { namespace detail {
+
+/**
+ This only holds the time format, and allows writing a certain time
+*/
+struct time_format_holder {
+private:
+ struct index_info {
+ typedef hold_string_type::size_type uint;
+
+ index_info(uint src_idx, int *format_idx, int size = 2) : src_idx(src_idx), format_idx(format_idx), size(size) {}
+ uint src_idx;
+ int * format_idx;
+ int size;
+
+ static bool by_index(const index_info & first, const index_info & second) {
+ return first.src_idx < second.src_idx;
+ }
+ };
+
+public:
+ bool operator==(const time_format_holder & other) const {
+ return m_format == other.m_format;
+ }
+
+
+ /**
+ constructs a time format holder object
+ */
+ time_format_holder(const hold_string_type & format) : m_day(-1), m_month(-1), m_yy(-1), m_yyyy(-1), m_hour(-1), m_min(-1), m_sec(-1),m_millisec(-1),m_microsec(-1),m_nanosec(-1) {
+ // format too big
+ BOOST_ASSERT( format.size() < 64);
+
+ typedef hold_string_type::size_type uint;
+ uint day_idx = format.find(BOOST_LOG_STR("$dd"));
+ uint month_idx = format.find(BOOST_LOG_STR("$MM"));
+ uint yy_idx = format.find(BOOST_LOG_STR("$yy"));
+ uint yyyy_idx = format.find(BOOST_LOG_STR("$yyyy"));
+ uint hour_idx = format.find(BOOST_LOG_STR("$hh"));
+ uint min_idx = format.find(BOOST_LOG_STR("$mm"));
+ uint sec_idx = format.find(BOOST_LOG_STR("$ss"));
+ uint millisec_idx = format.find(BOOST_LOG_STR("$mili"));
+ uint microsec_idx = format.find(BOOST_LOG_STR("$micro"));
+ uint nanosec_idx = format.find(BOOST_LOG_STR("$nano"));
+
+ typedef std::vector<index_info> array;
+ array indexes;
+ if ( day_idx != hold_string_type::npos)
+ indexes.push_back( index_info(day_idx, &m_day) );
+ if ( month_idx != hold_string_type::npos)
+ indexes.push_back( index_info(month_idx, &m_month) );
+
+ if ( yy_idx != hold_string_type::npos || yyyy_idx != hold_string_type::npos) {
+ if ( yyyy_idx != hold_string_type::npos)
+ indexes.push_back( index_info(yyyy_idx, &m_yyyy, 4) );
+ else
+ indexes.push_back( index_info(yy_idx, &m_yy) );
+ }
+
+ if ( hour_idx != hold_string_type::npos)
+ indexes.push_back( index_info(hour_idx, &m_hour ) );
+ if ( min_idx != hold_string_type::npos)
+ indexes.push_back( index_info(min_idx, &m_min) );
+ if ( sec_idx != hold_string_type::npos)
+ indexes.push_back( index_info(sec_idx, &m_sec) );
+ if ( millisec_idx != hold_string_type::npos)
+ indexes.push_back( index_info(millisec_idx, &m_millisec, 3) );
+ if ( microsec_idx != hold_string_type::npos)
+ indexes.push_back( index_info(microsec_idx, &m_microsec, 6) );
+ if ( nanosec_idx != hold_string_type::npos)
+ indexes.push_back( index_info(nanosec_idx, &m_nanosec, 9) );
+
+ std::sort( indexes.begin(), indexes.end(), index_info::by_index);
+
+ // create the format string, that we can actually pass to sprintf
+ uint prev_idx = 0;
+ int idx = 0;
+ for ( array::iterator begin = indexes.begin(), end = indexes.end(); begin != end; ++begin) {
+ m_format += format.substr( prev_idx, begin->src_idx - prev_idx);
+ *begin->format_idx = idx;
+ std::basic_ostringstream<char_type> cur_sprintf_format;
+ cur_sprintf_format << BOOST_LOG_STR("%0") << begin->size << BOOST_LOG_STR("d");
+ m_format += cur_sprintf_format.str();
+ prev_idx = begin->src_idx + begin->size + 1;
+ ++idx;
+ }
+
+ m_format += format.substr(prev_idx);
+ }
+
+ void write_time(char_type buffer[], int day, int month, int year, int hour, int min, int sec, int millisec, int microsec, int nanosec) const {
+ int vals[11];
+ vals[m_day + 1] = day;
+ vals[m_month + 1] = month;
+ vals[m_yy + 1] = year % 100;
+ vals[m_yyyy + 1] = year;
+ vals[m_hour + 1] = hour;
+ vals[m_min + 1] = min;
+ vals[m_sec + 1] = sec;
+ vals[m_millisec + 1] = millisec;
+ vals[m_microsec + 1] = microsec;
+ vals[m_nanosec + 1] = nanosec;
+
+ // ignore value at index 0 - it's there so that I don't have to test for an index being -1
+ #ifdef BOOST_LOG_USE_WCHAR_T
+ swprintf( buffer, m_format.c_str(), vals[1], vals[2], vals[3], vals[4], vals[5], vals[6], vals[7], vals[8], vals[9], vals[10] );
+ #else
+ sprintf( buffer, m_format.c_str(), vals[1], vals[2], vals[3], vals[4], vals[5], vals[6], vals[7], vals[8], vals[9], vals[10] );
+ #endif
+ }
+
+ void write_time(char_type buffer[], int day, int month, int year, int hour, int min, int sec) const {
+ int vals[8];
+ vals[m_day + 1] = day;
+ vals[m_month + 1] = month;
+ vals[m_yy + 1] = year % 100;
+ vals[m_yyyy + 1] = year;
+ vals[m_hour + 1] = hour;
+ vals[m_min + 1] = min;
+ vals[m_sec + 1] = sec;
+
+ // ignore value at index 0 - it's there so that I don't have to test for an index being -1
+ #ifdef BOOST_LOG_USE_WCHAR_T
+ swprintf( buffer, m_format.c_str(), vals[1], vals[2], vals[3], vals[4], vals[5], vals[6], vals[7]);
+ #else
+ sprintf( buffer, m_format.c_str(), vals[1], vals[2], vals[3], vals[4], vals[5], vals[6], vals[7] );
+ #endif
+ }
+
+private:
+ // the indexes of each escape sequence within the format string
+ int m_day, m_month, m_yy, m_yyyy, m_hour, m_min, m_sec, m_millisec, m_microsec, m_nanosec;
+ hold_string_type m_format;
+};
+
+}}}
+
+#endif
+

Modified: sandbox/logging/boost/logging/format/formatter/defaults.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/formatter/defaults.hpp (original)
+++ sandbox/logging/boost/logging/format/formatter/defaults.hpp 2007-12-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -25,6 +25,7 @@
 #include <boost/logging/detail/manipulator.hpp>
 #include <boost/logging/format/formatter/convert_format.hpp>
 #include <boost/logging/format/formatter/time.hpp>
+#include <boost/logging/format/formatter/time_strf.hpp>
 #include <boost/logging/format/formatter/spacer.hpp>
 #include <stdio.h>
 #include <time.h>

Added: sandbox/logging/boost/logging/format/formatter/high_precision_time.hpp
==============================================================================
--- (empty file)
+++ sandbox/logging/boost/logging/format/formatter/high_precision_time.hpp 2007-12-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -0,0 +1,135 @@
+// 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_time_HPP_DEFINED
+#define JT28092007_high_precision_time_HPP_DEFINED
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#include <boost/logging/detail/fwd.hpp>
+
+#include <boost/logging/format/formatter/convert_format.hpp>
+#include <boost/logging/detail/manipulator.hpp> // is_generic
+#include <boost/logging/detail/time_format_holder.hpp>
+
+#include <boost/date_time/microsec_time_clock.hpp>
+#include <boost/date_time/posix_time/posix_time_types.hpp>
+#include <boost/date_time/posix_time/ptime.hpp>
+
+
+namespace boost { namespace logging { namespace formatter {
+
+
+/**
+@brief Prefixes the message with a high-precision time (. You pass the format string at construction.
+
+@code
+#include <boost/logging/format/formatter/high_precision_time.hpp>
+@endcode
+
+Internally, it uses boost::date_time::microsec_time_clock. So, our precision matches this class.
+
+The format can contain escape sequences:
+$dd - day, 2 digits
+$MM - month, 2 digits
+$yy - year, 2 digits
+$yyyy - year, 4 digits
+$hh - hour, 2 digits
+$mm - minute, 2 digits
+$ss - second, 2 digits
+$mili - milliseconds
+$micro - microseconds (if the high precision clock allows; otherwise, it pads zeros)
+$nano - nanoseconds (if the high precision clock allows; otherwise, it pads zeros)
+
+
+Example: high_precision_time("$mm:$ss:$micro");
+
+@param convert [optional] In case there needs to be a conversion between std::(w)string and the string that holds your logged message. See convert_format.
+For instance, you might use @ref boost::logging::optimize::cache_string_one_str "a cached_string class" (see @ref boost::logging::optimize "optimize namespace").
+*/
+template<class convert = do_convert_format::prepend> struct high_precision_time_t : is_generic {
+ typedef convert convert_type;
+
+ /**
+ constructs a high_precision_time object
+ */
+ high_precision_time_t(const hold_string_type & format) : m_format(format) {}
+
+ template<class msg_type> void write_high_precision_time(msg_type & msg, ::boost::posix_time::ptime val) const {
+ char_type buffer[64];
+
+ int nanosecs = val.time_of_day().fractional_seconds();
+ int digits = val.time_of_day().num_fractional_digits();
+ switch ( digits) {
+ case 0: break; // no high precision at all
+ case 1: nanosecs *= 100000000; break;
+ case 2: nanosecs *= 10000000; break;
+ case 3: nanosecs *= 1000000; break;
+ case 4: nanosecs *= 100000; break;
+ case 5: nanosecs *= 10000; break;
+ case 6: nanosecs *= 1000; break;
+ case 7: nanosecs *= 100; break;
+ case 8: nanosecs *= 10; break;
+ case 9: break;
+ default:
+ while ( digits > 9) {
+ nanosecs /= 10; digits--;
+ }
+ break;
+ }
+
+ m_format.write_time( buffer,
+ val.date().day(),
+ val.date().month(),
+ val.date().year(),
+ val.time_of_day().hours(),
+ val.time_of_day().minutes(),
+ val.time_of_day().seconds(),
+ nanosecs / 1000000,
+ nanosecs / 1000,
+ nanosecs
+ );
+
+ convert::write(buffer, msg);
+ }
+
+ template<class msg_type> void operator()(msg_type & msg) const {
+ write_high_precision_time(msg, ::boost::posix_time::microsec_clock::local_time() );
+ }
+
+ bool operator==(const high_precision_time_t & other) const {
+ return m_format == other.m_format;
+ }
+
+private:
+ boost::logging::detail::time_format_holder m_format;
+};
+
+
+
+/** @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;
+
+
+}}}
+
+#endif
+

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-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -192,6 +192,10 @@
 /**
 @brief Allows you to contain multiple formatters, and specify a %spacer between them. You have a %spacer string, and within it, you can escape your contained formatters.
 
+@code
+#include <boost/logging/format/formatter/named_spacer.hpp>
+@endcode
+
 This allows you:
 - to hold multiple formatters
 - each formatter is given a name, when being added

Modified: sandbox/logging/boost/logging/format/formatter/time.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/formatter/time.hpp (original)
+++ sandbox/logging/boost/logging/format/formatter/time.hpp 2007-12-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -24,7 +24,8 @@
 #include <boost/logging/detail/fwd.hpp>
 #include <boost/logging/format/formatter/convert_format.hpp>
 #include <boost/logging/detail/manipulator.hpp> // is_generic
-#include <stdio.h>
+#include <boost/logging/detail/time_format_holder.hpp>
+
 #include <time.h>
 
 namespace boost { namespace logging { namespace formatter {
@@ -45,102 +46,24 @@
 
 Example: time("Today is $dd/$MM/$yyyy");
 
+Note: for a high precision clock, try high_precision_time (uses boost::date_time)
+
 @param convert [optional] In case there needs to be a conversion between std::(w)string and the string that holds your logged message. See convert_format.
 For instance, you might use @ref boost::logging::optimize::cache_string_one_str "a cached_string class" (see @ref boost::logging::optimize "optimize namespace").
 */
 template<class convert = do_convert_format::prepend> struct time_t : is_generic {
     typedef convert convert_type;
-private:
-
- struct index_info {
- typedef hold_string_type::size_type uint;
-
- index_info(uint src_idx, int *format_idx, int size = 2) : src_idx(src_idx), format_idx(format_idx), size(size) {}
- uint src_idx;
- int * format_idx;
- int size;
-
- static bool by_index(const index_info & first, const index_info & second) {
- return first.src_idx < second.src_idx;
- }
- };
-
-public:
 
     /**
         constructs a time object
     */
- time_t(const hold_string_type & format) : m_day(-1), m_month(-1), m_yy(-1), m_yyyy(-1), m_hour(-1), m_min(-1), m_sec(-1) {
- // format too big
- assert( format.size() < 64);
-
- typedef hold_string_type::size_type uint;
- uint day_idx = format.find(BOOST_LOG_STR("$dd"));
- uint month_idx = format.find(BOOST_LOG_STR("$MM"));
- uint yy_idx = format.find(BOOST_LOG_STR("$yy"));
- uint yyyy_idx = format.find(BOOST_LOG_STR("$yyyy"));
- uint hour_idx = format.find(BOOST_LOG_STR("$hh"));
- uint min_idx = format.find(BOOST_LOG_STR("$mm"));
- uint sec_idx = format.find(BOOST_LOG_STR("$ss"));
-
- typedef std::vector<index_info> array;
- array indexes;
- if ( day_idx != hold_string_type::npos)
- indexes.push_back( index_info(day_idx, &m_day) );
- if ( month_idx != hold_string_type::npos)
- indexes.push_back( index_info(month_idx, &m_month) );
-
- if ( yy_idx != hold_string_type::npos || yyyy_idx != hold_string_type::npos) {
- if ( yyyy_idx != hold_string_type::npos)
- indexes.push_back( index_info(yyyy_idx, &m_yyyy, 4) );
- else
- indexes.push_back( index_info(yy_idx, &m_yy) );
- }
-
- if ( hour_idx != hold_string_type::npos)
- indexes.push_back( index_info(hour_idx, &m_hour ) );
- if ( min_idx != hold_string_type::npos)
- indexes.push_back( index_info(min_idx, &m_min) );
- if ( sec_idx != hold_string_type::npos)
- indexes.push_back( index_info(sec_idx, &m_sec) );
- std::sort( indexes.begin(), indexes.end(), index_info::by_index);
-
- // create the format string, that we can actually pass to sprintf
- uint prev_idx = 0;
- int idx = 0;
- for ( typename array::iterator begin = indexes.begin(), end = indexes.end(); begin != end; ++begin) {
- m_format += format.substr( prev_idx, begin->src_idx - prev_idx);
- *begin->format_idx = idx;
- m_format += (begin->size == 4) ? BOOST_LOG_STR("%04d") : BOOST_LOG_STR("%02d");
- prev_idx = begin->src_idx + begin->size + 1;
- ++idx;
- }
-
- m_format += format.substr(prev_idx);
- }
-
-
+ time_t(const hold_string_type & format) : m_format(format) {}
 
     template<class msg_type> void write_time(msg_type & msg, ::time_t val) const {
         char_type buffer[64];
 
         tm details = *localtime( &val);
-
- int vals[8];
- vals[m_day + 1] = details.tm_mday;
- vals[m_month + 1] = details.tm_mon + 1; // many thanks to Matthew P. Cashdollar
- vals[m_yy + 1] = details.tm_year % 100; // many thanks to Andy Schweitzer
- vals[m_yyyy + 1] = details.tm_year + 1900;
- vals[m_hour + 1] = details.tm_hour;
- vals[m_min + 1] = details.tm_min;
- vals[m_sec + 1] = details.tm_sec;
-
- // ignore value at index 0 - it's there so that I don't have to test for an index being -1
- #ifdef BOOST_LOG_USE_WCHAR_T
- swprintf( buffer, m_format.c_str(), vals[1], vals[2], vals[3], vals[4], vals[5], vals[6], vals[7] );
- #else
- sprintf( buffer, m_format.c_str(), vals[1], vals[2], vals[3], vals[4], vals[5], vals[6], vals[7] );
- #endif
+ m_format.write_time( buffer, details.tm_mday, details.tm_mon + 1, details.tm_year + 1900, details.tm_hour, details.tm_min, details.tm_sec);
 
         convert::write(buffer, msg);
     }
@@ -155,55 +78,10 @@
     }
 
 private:
- // the indexes of each escape sequence within the format string
- int m_day, m_month, m_yy, m_yyyy, m_hour, m_min, m_sec;
- hold_string_type m_format;
+ boost::logging::detail::time_format_holder m_format;
 };
 
 
-/**
-_at_brief Prefixes the message with the time, by using strftime function. You pass the format string at construction.
-
-_at_param msg_type The type that holds your logged message.
-
-_at_param convert [optional] In case there needs to be a conversion between std::(w)string and the string that holds your logged message. See convert_format.
-For instance, you might use @ref boost::logging::optimize::cache_string_one_str "a cached_string class" (see @ref boost::logging::optimize "optimize namespace").
-*/
-template<class convert = do_convert_format::prepend> struct time_strf_t : is_generic {
- typedef convert convert_type;
-
- /**
- constructs a time_strf object
-
- @param format the time format , strftime-like
- @param localtime if true, use localtime, otherwise global time
- */
- time_strf_t(const hold_string_type & format, bool localtime)
- : m_format (format), m_localtime (localtime)
- {}
-
- template<class msg_type> void operator()(msg_type & msg) const {
- char_type buffer[64];
- ::time_t t = ::time (0);
- ::tm t_details = m_localtime ? *localtime( &t) : *gmtime( &t);
- #ifdef BOOST_LOG_USE_WCHAR_T
- if (0 != wcsftime (buffer, sizeof (buffer), m_format.c_str (), &t_details))
- #else
- if (0 != strftime (buffer, sizeof (buffer), m_format.c_str (), &t_details))
- #endif
- convert::write(buffer, msg);
- }
-
- bool operator==(const time_strf_t & other) const {
- return m_format == other.m_format;
- }
-
-private:
- hold_string_type m_format;
- bool m_localtime;
-
-};
-
 
 /** @brief time_t with default values. See time_t
 
@@ -211,11 +89,6 @@
 */
 typedef time_t<> time;
 
-/** @brief time_strf_t with default values. See time_strf_t
-
-_at_copydoc time_strf_t
-*/
-typedef time_strf_t<> time_strf;
 
 }}}
 

Added: sandbox/logging/boost/logging/format/formatter/time_strf.hpp
==============================================================================
--- (empty file)
+++ sandbox/logging/boost/logging/format/formatter/time_strf.hpp 2007-12-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -0,0 +1,87 @@
+// formatter_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_formatter_time_strf_HPP_DEFINED
+#define JT28092007_formatter_time_strf_HPP_DEFINED
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#include <boost/logging/detail/fwd.hpp>
+#include <boost/logging/format/formatter/convert_format.hpp>
+#include <boost/logging/detail/manipulator.hpp> // is_generic
+#include <stdio.h>
+#include <time.h>
+
+namespace boost { namespace logging { namespace formatter {
+
+
+/**
+@brief Prefixes the message with the time, by using strftime function. You pass the format string at construction.
+
+@param msg_type The type that holds your logged message.
+
+@param convert [optional] In case there needs to be a conversion between std::(w)string and the string that holds your logged message. See convert_format.
+For instance, you might use @ref boost::logging::optimize::cache_string_one_str "a cached_string class" (see @ref boost::logging::optimize "optimize namespace").
+*/
+template<class convert = do_convert_format::prepend> struct time_strf_t : is_generic {
+ typedef convert convert_type;
+
+ /**
+ constructs a time_strf object
+
+ @param format the time format , strftime-like
+ @param localtime if true, use localtime, otherwise global time
+ */
+ time_strf_t(const hold_string_type & format, bool localtime)
+ : m_format (format), m_localtime (localtime)
+ {}
+
+ template<class msg_type> void operator()(msg_type & msg) const {
+ char_type buffer[64];
+ ::time_t t = ::time (0);
+ ::tm t_details = m_localtime ? *localtime( &t) : *gmtime( &t);
+ #ifdef BOOST_LOG_USE_WCHAR_T
+ if (0 != wcsftime (buffer, sizeof (buffer), m_format.c_str (), &t_details))
+ #else
+ if (0 != strftime (buffer, sizeof (buffer), m_format.c_str (), &t_details))
+ #endif
+ convert::write(buffer, msg);
+ }
+
+ bool operator==(const time_strf_t & other) const {
+ return m_format == other.m_format;
+ }
+
+private:
+ hold_string_type m_format;
+ bool m_localtime;
+
+};
+
+
+
+/** @brief time_strf_t with default values. See time_strf_t
+
+@copydoc time_strf_t
+*/
+typedef time_strf_t<> time_strf;
+
+}}}
+
+#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-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -212,7 +212,7 @@
                         <Tool
                                 Name="VCLinkerTool"
                                 LinkIncremental="2"
- AdditionalLibraryDirectories="D:\boosts\boost_1_33_1\bin\boost\libs\thread\build\libboost_thread.lib\vc-8_0\debug\threading-multi"
+ AdditionalLibraryDirectories="D:\boosts\boost_1_33_1\bin\boost\libs\thread\build\libboost_thread.lib\vc-8_0\debug\threading-multi;D:\boosts\boost_1_33_1\bin\boost\libs\date_time\build\libboost_date_time.lib\vc-8_0\debug\threading-multi"
                                 GenerateDebugInformation="true"
                                 SubSystem="1"
                                 TargetMachine="1"
@@ -328,14 +328,6 @@
                         <File
                                 RelativePath=".\test_now.cpp"
>
- <FileConfiguration
- Name="Test|Win32"
- ExcludedFromBuild="true"
- >
- <Tool
- Name="VCCLCompilerTool"
- />
- </FileConfiguration>
                         </File>
                 </Filter>
                 <Filter
@@ -454,6 +446,10 @@
>
                         </File>
                         <File
+ RelativePath="..\..\..\..\..\boost\logging\detail\time_format_holder.hpp"
+ >
+ </File>
+ <File
                                 RelativePath="..\..\..\..\..\boost\logging\detail\util.hpp"
>
                         </File>
@@ -552,6 +548,10 @@
>
                                         </File>
                                         <File
+ RelativePath="..\..\..\..\..\boost\logging\format\formatter\high_precision_time.hpp"
+ >
+ </File>
+ <File
                                                 RelativePath="..\..\..\..\..\boost\logging\format\formatter\named_spacer.hpp"
>
                                         </File>
@@ -571,6 +571,10 @@
                                                 RelativePath="..\..\..\..\..\boost\logging\format\formatter\time.hpp"
>
                                         </File>
+ <File
+ RelativePath="..\..\..\..\..\boost\logging\format\formatter\time_strf.hpp"
+ >
+ </File>
                                 </Filter>
                                 <Filter
                                         Name="destination"
@@ -874,6 +878,7 @@
>
                                 <FileConfiguration
                                         Name="Test|Win32"
+ ExcludedFromBuild="true"
>
                                         <Tool
                                                 Name="VCCLCompilerTool"

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-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -31,16 +31,14 @@
 
 
 
-#define BOOST_LOG_COMPILE_FAST_OFF
 #include <boost/logging/format_fwd.hpp>
 
 // Step 1: Optimize : use a cache string, to make formatting the message faster
 BOOST_LOG_FORMAT_MSG( optimize::cache_string_one_str<> )
 
 #include <boost/logging/format.hpp>
-#include <boost/logging/format/formatter/thread_id.hpp>
-#include <boost/logging/format/formatter/named_spacer.hpp>
 #include <boost/logging/writer/ts_write.hpp>
+#include <boost/logging/format/formatter/high_precision_time.hpp>
 
 using namespace boost::logging;
 
@@ -60,18 +58,11 @@
 BOOST_DEFINE_LOG(g_l, log_type)
 
 
-
 void one_logger_one_filter_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::named_spacer("[%idx%] %time% (T%thread%) ")
- .add( "idx", formatter::idx())
- .add( "thread", formatter::thread_id())
- .add( "time", formatter::time("$mm"))
- );
-
+ g_l->writer().add_formatter( formatter::high_precision_time("$hh:$mm:$ss:$mili ") );
     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() );

Modified: sandbox/logging/lib/logging/samples/scenarios/custom_fmt_dest.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/custom_fmt_dest.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/custom_fmt_dest.cpp 2007-12-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -57,7 +57,6 @@
 
 
 
-#define BOOST_LOG_COMPILE_FAST_ON
 #include <boost/logging/format_fwd.hpp>
 
 // Step 1: Optimize : use a cache string, to make formatting the message faster

Modified: sandbox/logging/lib/logging/samples/scenarios/ded_loger_one_filter.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/ded_loger_one_filter.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/ded_loger_one_filter.cpp 2007-12-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -54,7 +54,6 @@
 
 
 
-#define BOOST_LOG_COMPILE_FAST_OFF
 #include <boost/logging/format_fwd.hpp>
 // Step 1: Optimize : use a cache string, to make formatting the message faster
 BOOST_LOG_FORMAT_MSG( optimize::cache_string_one_str<> )

Modified: sandbox/logging/lib/logging/samples/scenarios/mul_levels_mul_logers.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/mul_levels_mul_logers.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/mul_levels_mul_logers.cpp 2007-12-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -59,7 +59,6 @@
 
 
 
-#define BOOST_LOG_COMPILE_FAST_ON
 #include <boost/logging/format_fwd.hpp>
 
 // Step 1: Optimize : use a cache string, to make formatting the message faster

Modified: sandbox/logging/lib/logging/samples/scenarios/mul_levels_one_logger.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/mul_levels_one_logger.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/mul_levels_one_logger.cpp 2007-12-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -28,7 +28,6 @@
 
 
 
-#define BOOST_LOG_COMPILE_FAST_OFF
 #include <boost/logging/format.hpp>
 #include <boost/logging/writer/ts_write.hpp>
 

Modified: sandbox/logging/lib/logging/samples/scenarios/mul_loggers_one_filter.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/mul_loggers_one_filter.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/mul_loggers_one_filter.cpp 2007-12-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -58,7 +58,6 @@
 
 
 
-#define BOOST_LOG_COMPILE_FAST_OFF
 #include <boost/logging/format_fwd.hpp>
 
 // Step 1: Optimize : use a cache string, to make formatting the message faster

Modified: sandbox/logging/lib/logging/samples/scenarios/no_levels_with_route.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/no_levels_with_route.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/no_levels_with_route.cpp 2007-12-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -51,7 +51,6 @@
 
 
 
-#define BOOST_LOG_COMPILE_FAST_OFF
 #include <boost/logging/format_fwd.hpp>
 
 // Step 1: Optimize : use a cache string, to make formatting the message faster

Modified: sandbox/logging/lib/logging/samples/scenarios/one_loger_one_filter.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/one_loger_one_filter.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/one_loger_one_filter.cpp 2007-12-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -31,7 +31,6 @@
 
 
 
-#define BOOST_LOG_COMPILE_FAST_OFF
 #include <boost/logging/format_fwd.hpp>
 
 // Step 1: Optimize : use a cache string, to make formatting the message faster

Modified: sandbox/logging/lib/logging/samples/scenarios/ts_loger_one_filter.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/ts_loger_one_filter.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/ts_loger_one_filter.cpp 2007-12-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -47,7 +47,6 @@
 
 
 
-#define BOOST_LOG_COMPILE_FAST_OFF
 #include <boost/logging/format_fwd.hpp>
 // Step 1: Optimize : use a cache string, to make formatting the message faster
 BOOST_LOG_FORMAT_MSG( optimize::cache_string_one_str<> )

Modified: sandbox/logging/lib/logging/samples/scenarios/using_tags.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/using_tags.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/using_tags.cpp 2007-12-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -28,7 +28,6 @@
 
 
 
-#define BOOST_LOG_COMPILE_FAST_OFF
 #include <boost/logging/format_fwd.hpp>
 #include <boost/logging/tags.hpp>
 

Modified: sandbox/logging/lib/logging/samples/scenarios/your_scenario.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/your_scenario.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/your_scenario.cpp 2007-12-01 06:12:07 EST (Sat, 01 Dec 2007)
@@ -63,7 +63,6 @@
 
 
 
-#define BOOST_LOG_COMPILE_FAST_OFF
 #include <boost/logging/format_fwd.hpp>
 
 // Step 1: Optimize : use a cache string, to make formatting the message faster


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