Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85713 - in branches/release: boost/log boost/log/detail libs/log libs/log/doc libs/log/src
From: andrey.semashev_at_[hidden]
Date: 2013-09-16 14:58:52


Author: andysem
Date: 2013-09-16 14:58:52 EDT (Mon, 16 Sep 2013)
New Revision: 85713
URL: http://svn.boost.org/trac/boost/changeset/85713

Log:
Merged changes from trunk.

Properties modified:
   branches/release/boost/log/ (props changed)
   branches/release/libs/log/ (props changed)
Text files modified:
   branches/release/boost/log/detail/thread_id.hpp | 2 +-
   branches/release/libs/log/doc/changelog.qbk | 1 +
   branches/release/libs/log/doc/expressions.qbk | 6 +++---
   branches/release/libs/log/src/core.cpp | 5 +++++
   branches/release/libs/log/src/default_sink.cpp | 25 +++++++++++++++++++++----
   branches/release/libs/log/src/thread_id.cpp | 23 ++++++++++++++++++++++-
   6 files changed, 53 insertions(+), 9 deletions(-)

Modified: branches/release/boost/log/detail/thread_id.hpp
==============================================================================
--- branches/release/boost/log/detail/thread_id.hpp Mon Sep 16 14:42:58 2013 (r85712)
+++ branches/release/boost/log/detail/thread_id.hpp 2013-09-16 14:58:52 EDT (Mon, 16 Sep 2013) (r85713)
@@ -48,7 +48,7 @@
 //! The function returns current thread identifier
 BOOST_LOG_API thread::id const& get_id();
 
-} // namespace this_process
+} // namespace this_thread
 
 template< typename CharT, typename TraitsT >
 BOOST_LOG_API std::basic_ostream< CharT, TraitsT >&

Modified: branches/release/libs/log/doc/changelog.qbk
==============================================================================
--- branches/release/libs/log/doc/changelog.qbk Mon Sep 16 14:42:58 2013 (r85712)
+++ branches/release/libs/log/doc/changelog.qbk 2013-09-16 14:58:52 EDT (Mon, 16 Sep 2013) (r85713)
@@ -23,6 +23,7 @@
 
 * Fixed [link log.detailed.attributes.timer `timer`] attribute generating incorrect time readings on Windows on heavy thread contention when `QueryPerformanceCounter` API was used.
 * Fixed a bug in the filter parser that prevented using parsed filters with some attributes. For example, parsed filters didn't work with a string-typed attribute value, if the value was compared to a numeric operand.
+* Fixed thread id formatting discrepancies between the default sink and formatters.
 * Closed tickets: [ticket 8815], [ticket 8819], [ticket 8915], [ticket 8917].
 
 [heading 2.1, Boost 1.54]

Modified: branches/release/libs/log/doc/expressions.qbk
==============================================================================
--- branches/release/libs/log/doc/expressions.qbk Mon Sep 16 14:42:58 2013 (r85712)
+++ branches/release/libs/log/doc/expressions.qbk 2013-09-16 14:58:52 EDT (Mon, 16 Sep 2013) (r85713)
@@ -388,7 +388,7 @@
     sink->set_formatter
     (
         expr::stream
- << expr::named_scope(
+ << expr::format_named_scope(
                 "Scopes",
                 keywords::format = "%n",
                 keywords::iteration = expr::reverse,
@@ -400,7 +400,7 @@
     sink->set_formatter
     (
         expr::stream
- << expr::named_scope(
+ << expr::format_named_scope(
                 "Scopes",
                 keywords::format = "%n",
                 keywords::iteration = expr::forward,
@@ -412,7 +412,7 @@
     sink->set_formatter
     (
         expr::stream
- << expr::named_scope(
+ << expr::format_named_scope(
                 "Scopes",
                 keywords::format = "%n",
                 keywords::iteration = expr::reverse,

Modified: branches/release/libs/log/src/core.cpp
==============================================================================
--- branches/release/libs/log/src/core.cpp Mon Sep 16 14:42:58 2013 (r85712)
+++ branches/release/libs/log/src/core.cpp 2013-09-16 14:58:52 EDT (Mon, 16 Sep 2013) (r85713)
@@ -20,6 +20,7 @@
 #include <algorithm>
 #include <boost/cstdint.hpp>
 #include <boost/assert.hpp>
+#include <boost/filesystem/path.hpp>
 #include <boost/smart_ptr/weak_ptr.hpp>
 #include <boost/smart_ptr/shared_ptr.hpp>
 #include <boost/smart_ptr/make_shared_object.hpp>
@@ -251,6 +252,10 @@
         m_default_sink(boost::make_shared< sinks::aux::default_sink >()),
         m_enabled(true)
     {
+ // Workaround for https://svn.boost.org/trac/boost/ticket/8642
+ // Initialize global locale in Boost.Filesystem early, so that it is still available while the logging core is destroyed.
+ // Note that this only helps in the simplest case, when the core is not kept alive by a shared_ptr saved by user.
+ filesystem::path::codecvt();
     }
 
     //! Invokes sink-specific filter and adds the sink to the record if the filter passes the log record

Modified: branches/release/libs/log/src/default_sink.cpp
==============================================================================
--- branches/release/libs/log/src/default_sink.cpp Mon Sep 16 14:42:58 2013 (r85712)
+++ branches/release/libs/log/src/default_sink.cpp 2013-09-16 14:58:52 EDT (Mon, 16 Sep 2013) (r85713)
@@ -31,6 +31,13 @@
 
 BOOST_LOG_OPEN_NAMESPACE
 
+namespace aux {
+
+// Defined in thread_id.cpp
+void format_thread_id(char* buf, std::size_t size, thread::id tid);
+
+} // namespace aux
+
 namespace sinks {
 
 namespace aux {
@@ -111,11 +118,16 @@
 
     result_type operator() (std::string const& msg) const
     {
+#if !defined(BOOST_LOG_NO_THREADS)
+ char thread_id_buf[64];
+ boost::log::aux::format_thread_id(thread_id_buf, sizeof(thread_id_buf), boost::log::aux::this_thread::get_id());
+#endif
+
         const decomposed_time_point now = date_time::microsec_clock< decomposed_time_point >::local_time();
 
         std::printf("[%04u-%02u-%02u %02u:%02u:%02u.%06u] "
 #if !defined(BOOST_LOG_NO_THREADS)
- "[0x%08x] "
+ "[%s] "
 #endif
                     "%s %s\n",
             static_cast< unsigned int >(now.date.year),
@@ -126,7 +138,7 @@
             static_cast< unsigned int >(now.time.seconds),
             static_cast< unsigned int >(now.time.useconds),
 #if !defined(BOOST_LOG_NO_THREADS)
- static_cast< unsigned int >(boost::log::aux::this_thread::get_id().native_id()),
+ thread_id_buf,
 #endif
             severity_level_to_string(m_level),
             msg.c_str());
@@ -138,11 +150,16 @@
 
     result_type operator() (std::wstring const& msg) const
     {
+#if !defined(BOOST_LOG_NO_THREADS)
+ char thread_id_buf[64];
+ boost::log::aux::format_thread_id(thread_id_buf, sizeof(thread_id_buf), boost::log::aux::this_thread::get_id());
+#endif
+
         const decomposed_time_point now = date_time::microsec_clock< decomposed_time_point >::local_time();
 
         std::printf("[%04u-%02u-%02u %02u:%02u:%02u.%06u] "
 #if !defined(BOOST_LOG_NO_THREADS)
- "[0x%08x] "
+ "[%s] "
 #endif
                     "%s %ls\n",
             static_cast< unsigned int >(now.date.year),
@@ -153,7 +170,7 @@
             static_cast< unsigned int >(now.time.seconds),
             static_cast< unsigned int >(now.time.useconds),
 #if !defined(BOOST_LOG_NO_THREADS)
- static_cast< unsigned int >(boost::log::aux::this_thread::get_id().native_id()),
+ thread_id_buf,
 #endif
             severity_level_to_string(m_level),
             msg.c_str());

Modified: branches/release/libs/log/src/thread_id.cpp
==============================================================================
--- branches/release/libs/log/src/thread_id.cpp Mon Sep 16 14:42:58 2013 (r85712)
+++ branches/release/libs/log/src/thread_id.cpp 2013-09-16 14:58:52 EDT (Mon, 16 Sep 2013) (r85713)
@@ -226,6 +226,27 @@
 
 } // namespace this_thread
 
+// Used in default_sink.cpp
+void format_thread_id(char* buf, std::size_t size, thread::id tid)
+{
+ static const char char_table[] = "0123456789abcdef";
+
+ // Input buffer is assumed to be always larger than 2 chars
+ *buf++ = '0';
+ *buf++ = 'x';
+
+ size -= 3; // reserve space for the terminating 0
+ thread::id::native_type id = tid.native_id();
+ unsigned int i = 0;
+ const unsigned int n = (size > (tid_size * 2u)) ? static_cast< unsigned int >(tid_size * 2u) : static_cast< unsigned int >(size);
+ for (unsigned int shift = n * 4u; i < n; ++i, shift -= 4u)
+ {
+ buf[i] = char_table[(id >> shift) & 15u];
+ }
+
+ buf[i] = '\0';
+}
+
 template< typename CharT, typename TraitsT >
 std::basic_ostream< CharT, TraitsT >&
 operator<< (std::basic_ostream< CharT, TraitsT >& strm, thread::id const& tid)
@@ -233,8 +254,8 @@
     if (strm.good())
     {
         io::ios_flags_saver flags_saver(strm, (strm.flags() & std::ios_base::uppercase) | std::ios_base::hex | std::ios_base::internal | std::ios_base::showbase);
- io::ios_width_saver width_saver(strm, static_cast< std::streamsize >(tid_size * 2 + 2)); // 2 chars per byte + 2 chars for the leading 0x
         io::basic_ios_fill_saver< CharT, TraitsT > fill_saver(strm, static_cast< CharT >('0'));
+ strm.width(static_cast< std::streamsize >(tid_size * 2 + 2)); // 2 chars per byte + 2 chars for the leading 0x
         strm << static_cast< uint_t< tid_size * 8 >::least >(tid.native_id());
     }
 


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