2 * Copyright Andrey Semashev 2007 - 2015.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
8 * \file from_settings.hpp
9 * \author Andrey Semashev
12 * The header contains definition of facilities that allows to initialize the library from
16 #ifndef BOOST_LOG_UTILITY_SETUP_FROM_SETTINGS_HPP_INCLUDED_
17 #define BOOST_LOG_UTILITY_SETUP_FROM_SETTINGS_HPP_INCLUDED_
20 #include <boost/smart_ptr/shared_ptr.hpp>
21 #include <boost/core/enable_if.hpp>
22 #include <boost/type_traits/is_base_and_derived.hpp>
23 #include <boost/log/detail/setup_config.hpp>
24 #include <boost/log/sinks/sink.hpp>
25 #include <boost/log/utility/setup/settings.hpp>
26 #include <boost/log/detail/header.hpp>
28 #ifdef BOOST_HAS_PRAGMA_ONCE
34 BOOST_LOG_OPEN_NAMESPACE
37 * The function initializes the logging library from a settings container
39 * \param setts Library settings container
41 * \b Throws: An <tt>std::exception</tt>-based exception if the provided settings are not valid.
43 template< typename CharT >
44 BOOST_LOG_SETUP_API void init_from_settings(basic_settings_section< CharT > const& setts);
48 * Sink factory base interface
50 template< typename CharT >
54 typedef CharT char_type;
56 typedef std::basic_string< char_type > string_type;
57 //! Settings section type
58 typedef basic_settings_section< char_type > settings_section;
63 BOOST_DEFAULTED_FUNCTION(sink_factory(), {})
68 virtual ~sink_factory() {}
71 * The function creates a formatter for the specified attribute.
73 * \param settings Sink parameters
75 virtual shared_ptr< sinks::sink > create_sink(settings_section const& settings) = 0;
77 BOOST_DELETED_FUNCTION(sink_factory(sink_factory const&))
78 BOOST_DELETED_FUNCTION(sink_factory& operator= (sink_factory const&))
82 * \brief The function registers a factory for a custom sink
84 * The function registers a factory for a sink. The factory will be called to create sink
85 * instance when the parser discovers the specified sink type in the settings file. The
86 * factory must accept a map of parameters [parameter name -> parameter value] that it
87 * may use to initialize the sink. The factory must return a non-NULL pointer to the
88 * constructed sink instance.
90 * \param sink_name The custom sink name. Must point to a zero-terminated sequence of characters,
92 * \param factory Pointer to the custom sink factory. Must not be NULL.
94 template< typename CharT >
95 BOOST_LOG_SETUP_API void register_sink_factory(const char* sink_name, shared_ptr< sink_factory< CharT > > const& factory);
98 * \brief The function registers a factory for a custom sink
100 * The function registers a factory for a sink. The factory will be called to create sink
101 * instance when the parser discovers the specified sink type in the settings file. The
102 * factory must accept a map of parameters [parameter name -> parameter value] that it
103 * may use to initialize the sink. The factory must return a non-NULL pointer to the
104 * constructed sink instance.
106 * \param sink_name The custom sink name
107 * \param factory Pointer to the custom sink factory. Must not be NULL.
109 template< typename CharT >
110 inline void register_sink_factory(std::string const& sink_name, shared_ptr< sink_factory< CharT > > const& factory)
112 register_sink_factory(sink_name.c_str(), factory);
116 * \brief The function registers a factory for a custom sink
118 * The function registers a factory for a sink. The factory will be called to create sink
119 * instance when the parser discovers the specified sink type in the settings file. The
120 * factory must accept a map of parameters [parameter name -> parameter value] that it
121 * may use to initialize the sink. The factory must return a non-NULL pointer to the
122 * constructed sink instance.
124 * \param sink_name The custom sink name. Must point to a zero-terminated sequence of characters,
126 * \param factory Pointer to the custom sink factory. Must not be NULL.
128 template< typename FactoryT >
129 inline typename boost::enable_if_c<
130 is_base_and_derived< sink_factory< typename FactoryT::char_type >, FactoryT >::value
131 >::type register_sink_factory(const char* sink_name, shared_ptr< FactoryT > const& factory)
133 typedef sink_factory< typename FactoryT::char_type > factory_base;
134 register_sink_factory(sink_name, boost::static_pointer_cast< factory_base >(factory));
138 * \brief The function registers a factory for a custom sink
140 * The function registers a factory for a sink. The factory will be called to create sink
141 * instance when the parser discovers the specified sink type in the settings file. The
142 * factory must accept a map of parameters [parameter name -> parameter value] that it
143 * may use to initialize the sink. The factory must return a non-NULL pointer to the
144 * constructed sink instance.
146 * \param sink_name The custom sink name
147 * \param factory Pointer to the custom sink factory. Must not be NULL.
149 template< typename FactoryT >
150 inline typename boost::enable_if_c<
151 is_base_and_derived< sink_factory< typename FactoryT::char_type >, FactoryT >::value
152 >::type register_sink_factory(std::string const& sink_name, shared_ptr< FactoryT > const& factory)
154 typedef sink_factory< typename FactoryT::char_type > factory_base;
155 register_sink_factory(sink_name.c_str(), boost::static_pointer_cast< factory_base >(factory));
158 BOOST_LOG_CLOSE_NAMESPACE // namespace log
162 #include <boost/log/detail/footer.hpp>
164 #endif // BOOST_LOG_UTILITY_SETUP_FROM_SETTINGS_HPP_INCLUDED_