Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85031 - in trunk/libs/log: build doc src
From: andrey.semashev_at_[hidden]
Date: 2013-07-14 07:31:19


Author: andysem
Date: 2013-07-14 07:31:19 EDT (Sun, 14 Jul 2013)
New Revision: 85031
URL: http://svn.boost.org/trac/boost/changeset/85031

Log:
Extracted default formatter factory to a separate translation unit. Made all default factories optional, the factories can be disabled with the new config macro BOOST_LOG_WITHOUT_DEFAULT_FACTORIES. Refs #8773, #8786.

Added:
   trunk/libs/log/src/default_formatter_factory.cpp (contents, props changed)
   trunk/libs/log/src/default_formatter_factory.hpp (contents, props changed)
Text files modified:
   trunk/libs/log/build/Jamfile.v2 | 1
   trunk/libs/log/doc/log.qbk | 1
   trunk/libs/log/src/default_filter_factory.cpp | 4 +
   trunk/libs/log/src/default_formatter_factory.cpp | 98 ++++++++++++++++++++++++++++++++++++++++
   trunk/libs/log/src/default_formatter_factory.hpp | 58 +++++++++++++++++++++++
   trunk/libs/log/src/filter_parser.cpp | 12 ++++
   trunk/libs/log/src/formatter_parser.cpp | 80 ++++++++++++--------------------
   7 files changed, 204 insertions(+), 50 deletions(-)

Modified: trunk/libs/log/build/Jamfile.v2
==============================================================================
--- trunk/libs/log/build/Jamfile.v2 Sun Jul 14 06:08:57 2013 (r85030)
+++ trunk/libs/log/build/Jamfile.v2 2013-07-14 07:31:19 EDT (Sun, 14 Jul 2013) (r85031)
@@ -344,6 +344,7 @@
     filter_parser.cpp
     formatter_parser.cpp
     default_filter_factory.cpp
+ default_formatter_factory.cpp
     ;
 
 lib boost_log_setup

Modified: trunk/libs/log/doc/log.qbk
==============================================================================
--- trunk/libs/log/doc/log.qbk Sun Jul 14 06:08:57 2013 (r85030)
+++ trunk/libs/log/doc/log.qbk 2013-07-14 07:31:19 EDT (Sun, 14 Jul 2013) (r85031)
@@ -200,6 +200,7 @@
     [[`BOOST_LOG_WITHOUT_WCHAR_T`] [If defined, disables support for wide character logging. Affects the compilation of both the library and users' code.]]
     [[`BOOST_LOG_NO_QUERY_PERFORMANCE_COUNTER`] [This macro is only useful on Windows. It affects the compilation of both the library and users' code. If defined, disables support for the `QueryPerformanceCounter` API in the `timer` attribute. This will result in significantly less accurate time readings. The macro is intended to solve possible problems with earlier revisions of AMD Athlon CPU, described [@http://support.microsoft.com/?scid=kb;en-us;895980 here] and [@http://support.microsoft.com/?id=896256 here]. There are also known chipset hardware failures that may prevent this API from functioning properly (see [@http://support.microsoft.com/kb/274323 here]).]]
     [[`BOOST_LOG_USE_NATIVE_SYSLOG`] [Affects only the compilation of the library. If for some reason support for the native SysLog API is not detected automatically, define this macro to forcibly enable it]]
+ [[`BOOST_LOG_WITHOUT_DEFAULT_FACTORIES`] [Affects only the compilation of the library. If defined, the parsers for settings will be built without any default factories for filters and formatters. The user will have to register all attributes in the library before parsing any filters or formatters from strings. This can substantially reduce the binary size.]]
     [[`BOOST_LOG_WITHOUT_SETTINGS_PARSERS`] [Affects only the compilation of the library. If defined, none of the facilities related to the parsers for settings will be built. This can substantially reduce the binary size.]]
     [[`BOOST_LOG_WITHOUT_DEBUG_OUTPUT`] [Affects only the compilation of the library. If defined, the support for debugger output on Windows will not be built.]]
     [[`BOOST_LOG_WITHOUT_EVENT_LOG`] [Affects only the compilation of the library. If defined, the support for Windows event log will not be built. Defining the macro also makes Message Compiler toolset unnecessary.]]

Modified: trunk/libs/log/src/default_filter_factory.cpp
==============================================================================
--- trunk/libs/log/src/default_filter_factory.cpp Sun Jul 14 06:08:57 2013 (r85030)
+++ trunk/libs/log/src/default_filter_factory.cpp 2013-07-14 07:31:19 EDT (Sun, 14 Jul 2013) (r85031)
@@ -13,6 +13,8 @@
  * at http://www.boost.org/libs/log/doc/log.html.
  */
 
+#if !defined(BOOST_LOG_WITHOUT_DEFAULT_FACTORIES)
+
 #include <string>
 #include <boost/move/core.hpp>
 #include <boost/move/utility.hpp>
@@ -395,3 +397,5 @@
 } // namespace boost
 
 #include <boost/log/detail/footer.hpp>
+
+#endif // !defined(BOOST_LOG_WITHOUT_DEFAULT_FACTORIES)

Added: trunk/libs/log/src/default_formatter_factory.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/log/src/default_formatter_factory.cpp 2013-07-14 07:31:19 EDT (Sun, 14 Jul 2013) (r85031)
@@ -0,0 +1,98 @@
+/*
+ * Copyright Andrey Semashev 2007 - 2013.
+ * 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)
+ */
+/*!
+ * \file default_formatter_factory.hpp
+ * \author Andrey Semashev
+ * \date 14.07.2013
+ *
+ * \brief This header is the Boost.Log library implementation, see the library documentation
+ * at http://www.boost.org/libs/log/doc/log.html.
+ */
+
+#if !defined(BOOST_LOG_WITHOUT_DEFAULT_FACTORIES)
+
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/copy.hpp>
+#include <boost/mpl/push_back.hpp>
+#include <boost/mpl/back_inserter.hpp>
+#include <boost/date_time/gregorian/gregorian.hpp>
+#include <boost/date_time/local_time/local_time.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/phoenix/core.hpp>
+#include <boost/phoenix/operator.hpp>
+#include <boost/log/exceptions.hpp>
+#include <boost/log/expressions/attr.hpp>
+#include <boost/log/expressions/formatters/stream.hpp>
+#include <boost/log/utility/type_dispatch/standard_types.hpp>
+#include <boost/log/utility/type_dispatch/date_time_types.hpp>
+#include <boost/log/utility/string_literal.hpp>
+#include <boost/log/detail/code_conversion.hpp>
+#include <boost/log/detail/process_id.hpp>
+#if !defined(BOOST_LOG_NO_THREADS)
+#include <boost/log/detail/thread_id.hpp>
+#endif
+#include <boost/log/attributes/named_scope.hpp>
+#include "default_formatter_factory.hpp"
+#include <boost/log/detail/header.hpp>
+
+namespace boost {
+
+BOOST_LOG_OPEN_NAMESPACE
+
+namespace aux {
+
+//! The callback for equality relation filter
+template< typename CharT >
+typename default_formatter_factory< CharT >::formatter_type
+default_formatter_factory< CharT >::create_formatter(attribute_name const& name, args_map const& args)
+{
+ // No user-defined factory, shall use the most generic formatter we can ever imagine at this point
+ typedef mpl::copy<
+ // We have to exclude std::time_t since it's an integral type and will conflict with one of the standard types
+ boost_time_period_types,
+ mpl::back_inserter<
+ mpl::copy<
+ boost_time_duration_types,
+ mpl::back_inserter< boost_date_time_types >
+ >::type
+ >
+ >::type time_related_types;
+
+ typedef mpl::copy<
+ mpl::copy<
+ mpl::vector<
+ attributes::named_scope_list,
+#if !defined(BOOST_LOG_NO_THREADS)
+ log::aux::thread::id,
+#endif
+ log::aux::process::id
+ >,
+ mpl::back_inserter< time_related_types >
+ >::type,
+ mpl::back_inserter< default_attribute_types >
+ >::type supported_types;
+
+ return formatter_type(expressions::stream << expressions::attr< supported_types::type >(name));
+}
+
+// Explicitly instantiate factory implementation
+#ifdef BOOST_LOG_USE_CHAR
+template class default_formatter_factory< char >;
+#endif
+#ifdef BOOST_LOG_USE_WCHAR_T
+template class default_formatter_factory< wchar_t >;
+#endif
+
+} // namespace aux
+
+BOOST_LOG_CLOSE_NAMESPACE // namespace log
+
+} // namespace boost
+
+#include <boost/log/detail/footer.hpp>
+
+#endif // !defined(BOOST_LOG_WITHOUT_DEFAULT_FACTORIES)

Added: trunk/libs/log/src/default_formatter_factory.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/log/src/default_formatter_factory.hpp 2013-07-14 07:31:19 EDT (Sun, 14 Jul 2013) (r85031)
@@ -0,0 +1,58 @@
+/*
+ * Copyright Andrey Semashev 2007 - 2013.
+ * 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)
+ */
+/*!
+ * \file default_formatter_factory.hpp
+ * \author Andrey Semashev
+ * \date 14.07.2013
+ *
+ * \brief This header is the Boost.Log library implementation, see the library documentation
+ * at http://www.boost.org/libs/log/doc/log.html.
+ */
+
+#ifndef BOOST_DEFAULT_FORMATTER_FACTORY_HPP_INCLUDED_
+#define BOOST_DEFAULT_FORMATTER_FACTORY_HPP_INCLUDED_
+
+#include <boost/log/attributes/attribute_name.hpp>
+#include <boost/log/utility/setup/formatter_parser.hpp>
+#include <boost/log/detail/header.hpp>
+
+namespace boost {
+
+BOOST_LOG_OPEN_NAMESPACE
+
+namespace aux {
+
+//! The default filter factory that supports creating filters for the standard types (see utility/type_dispatch/standard_types.hpp)
+template< typename CharT >
+class default_formatter_factory :
+ public formatter_factory< CharT >
+{
+ //! Base type
+ typedef formatter_factory< CharT > base_type;
+ //! Self type
+ typedef default_formatter_factory< CharT > this_type;
+
+public:
+ // Type imports
+ typedef typename base_type::char_type char_type;
+ typedef typename base_type::string_type string_type;
+ typedef typename base_type::formatter_type formatter_type;
+ typedef typename base_type::args_map args_map;
+
+ //! The function creates a formatter for the specified attribute.
+ virtual formatter_type create_formatter(attribute_name const& name, args_map const& args);
+};
+
+} // namespace aux
+
+BOOST_LOG_CLOSE_NAMESPACE // namespace log
+
+} // namespace boost
+
+#include <boost/log/detail/footer.hpp>
+
+#endif // BOOST_DEFAULT_FORMATTER_FACTORY_HPP_INCLUDED_

Modified: trunk/libs/log/src/filter_parser.cpp
==============================================================================
--- trunk/libs/log/src/filter_parser.cpp Sun Jul 14 06:08:57 2013 (r85030)
+++ trunk/libs/log/src/filter_parser.cpp 2013-07-14 07:31:19 EDT (Sun, 14 Jul 2013) (r85031)
@@ -48,7 +48,9 @@
 #include <boost/log/detail/light_rw_mutex.hpp>
 #endif // !defined(BOOST_LOG_NO_THREADS)
 #include "parser_utils.hpp"
+#if !defined(BOOST_LOG_WITHOUT_DEFAULT_FACTORIES)
 #include "default_filter_factory.hpp"
+#endif
 #include "spirit_encoding.hpp"
 #include <boost/log/detail/header.hpp>
 
@@ -94,17 +96,27 @@
 #endif
     //! The map of filter factories
     factories_map m_Map;
+#if !defined(BOOST_LOG_WITHOUT_DEFAULT_FACTORIES)
     //! Default factory
     mutable aux::default_filter_factory< char_type > m_DefaultFactory;
+#endif
 
     //! The method returns the filter factory for the specified attribute name
     filter_factory_type& get_factory(attribute_name const& name) const
     {
         typename factories_map::const_iterator it = m_Map.find(name);
         if (it != m_Map.end())
+ {
             return *it->second;
+ }
         else
+ {
+#if !defined(BOOST_LOG_WITHOUT_DEFAULT_FACTORIES)
             return m_DefaultFactory;
+#else
+ BOOST_LOG_THROW_DESCR(setup_error, "No filter factory registered for attribute " + name.string());
+#endif
+ }
     }
 
 private:

Modified: trunk/libs/log/src/formatter_parser.cpp
==============================================================================
--- trunk/libs/log/src/formatter_parser.cpp Sun Jul 14 06:08:57 2013 (r85030)
+++ trunk/libs/log/src/formatter_parser.cpp 2013-07-14 07:31:19 EDT (Sun, 14 Jul 2013) (r85031)
@@ -27,10 +27,6 @@
 #include <boost/bind.hpp>
 #include <boost/move/core.hpp>
 #include <boost/move/utility.hpp>
-#include <boost/mpl/vector.hpp>
-#include <boost/mpl/copy.hpp>
-#include <boost/mpl/push_back.hpp>
-#include <boost/mpl/back_inserter.hpp>
 #include <boost/optional/optional.hpp>
 #include <boost/utility/in_place_factory.hpp>
 #include <boost/range/iterator_range_core.hpp>
@@ -43,30 +39,24 @@
 #include <boost/spirit/include/qi_symbols.hpp>
 #include <boost/phoenix/core.hpp>
 #include <boost/phoenix/operator.hpp>
-#include <boost/date_time/gregorian/gregorian.hpp>
-#include <boost/date_time/local_time/local_time.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/log/expressions/attr.hpp>
 #include <boost/log/expressions/message.hpp>
 #include <boost/log/expressions/formatters/stream.hpp>
 #include <boost/log/attributes/attribute_name.hpp>
-#include <boost/log/attributes/named_scope.hpp>
 #include <boost/log/exceptions.hpp>
 #include <boost/log/detail/singleton.hpp>
-#include <boost/log/detail/process_id.hpp>
 #include <boost/log/detail/code_conversion.hpp>
 #include <boost/log/detail/default_attribute_names.hpp>
 #include <boost/log/utility/functional/nop.hpp>
 #include <boost/log/utility/setup/formatter_parser.hpp>
-#include <boost/log/utility/type_dispatch/standard_types.hpp>
-#include <boost/log/utility/type_dispatch/date_time_types.hpp>
 #if !defined(BOOST_LOG_NO_THREADS)
-#include <boost/log/detail/thread_id.hpp>
 #include <boost/log/detail/locks.hpp>
 #include <boost/log/detail/light_rw_mutex.hpp>
 #endif
 #include "parser_utils.hpp"
 #include "spirit_encoding.hpp"
+#if !defined(BOOST_LOG_WITHOUT_DEFAULT_FACTORIES)
+#include "default_formatter_factory.hpp"
+#endif
 #include <boost/log/detail/header.hpp>
 
 namespace qi = boost::spirit::qi;
@@ -91,7 +81,8 @@
     friend class base_type;
 #endif
 
- typedef formatter_factory< CharT > formatter_factory_type;
+ typedef CharT char_type;
+ typedef formatter_factory< char_type > formatter_factory_type;
 
     //! Attribute name ordering predicate
     struct attribute_name_order
@@ -113,6 +104,28 @@
 #endif
     //! The map of formatter factories
     factories_map m_Map;
+#if !defined(BOOST_LOG_WITHOUT_DEFAULT_FACTORIES)
+ //! Default factory
+ mutable aux::default_formatter_factory< char_type > m_DefaultFactory;
+#endif
+
+ //! The method returns the filter factory for the specified attribute name
+ formatter_factory_type& get_factory(attribute_name const& name) const
+ {
+ typename factories_map::const_iterator it = m_Map.find(name);
+ if (it != m_Map.end())
+ {
+ return *it->second;
+ }
+ else
+ {
+#if !defined(BOOST_LOG_WITHOUT_DEFAULT_FACTORIES)
+ return m_DefaultFactory;
+#else
+ BOOST_LOG_THROW_DESCR(setup_error, "No formatter factory registered for attribute " + name.string());
+#endif
+ }
+ }
 
 private:
     formatters_repository()
@@ -326,43 +339,10 @@
         }
         else
         {
+ // Use the factory to create the formatter
             formatters_repository< char_type > const& repo = formatters_repository< char_type >::get();
- typename formatters_repository< char_type >::factories_map::const_iterator it = repo.m_Map.find(m_AttrName);
- if (it != repo.m_Map.end())
- {
- // We've found a user-defined factory for this attribute
- append_formatter(it->second->create_formatter(m_AttrName, m_FactoryArgs));
- }
- else
- {
- // No user-defined factory, shall use the most generic formatter we can ever imagine at this point
- typedef mpl::copy<
- // We have to exclude std::time_t since it's an integral type and will conflict with one of the standard types
- boost_time_period_types,
- mpl::back_inserter<
- mpl::copy<
- boost_time_duration_types,
- mpl::back_inserter< boost_date_time_types >
- >::type
- >
- >::type time_related_types;
-
- typedef mpl::copy<
- mpl::copy<
- mpl::vector<
- attributes::named_scope_list,
-#if !defined(BOOST_LOG_NO_THREADS)
- log::aux::thread::id,
-#endif
- log::aux::process::id
- >,
- mpl::back_inserter< time_related_types >
- >::type,
- mpl::back_inserter< default_attribute_types >
- >::type supported_types;
-
- append_formatter(expressions::stream << expressions::attr< supported_types::type >(m_AttrName));
- }
+ formatter_factory_type& factory = repo.get_factory(m_AttrName);
+ append_formatter(factory.create_formatter(m_AttrName, m_FactoryArgs));
         }
 
         // Eventually, clear all the auxiliary data


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