Chris@16
|
1 /*
|
Chris@101
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
Chris@16
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7 /*!
|
Chris@16
|
8 * \file from_settings.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 11.10.2009
|
Chris@16
|
11 *
|
Chris@16
|
12 * The header contains definition of facilities that allows to initialize the library from
|
Chris@16
|
13 * settings.
|
Chris@16
|
14 */
|
Chris@16
|
15
|
Chris@16
|
16 #ifndef BOOST_LOG_UTILITY_SETUP_FROM_SETTINGS_HPP_INCLUDED_
|
Chris@16
|
17 #define BOOST_LOG_UTILITY_SETUP_FROM_SETTINGS_HPP_INCLUDED_
|
Chris@16
|
18
|
Chris@16
|
19 #include <string>
|
Chris@16
|
20 #include <boost/smart_ptr/shared_ptr.hpp>
|
Chris@16
|
21 #include <boost/utility/enable_if.hpp>
|
Chris@16
|
22 #include <boost/type_traits/is_base_and_derived.hpp>
|
Chris@16
|
23 #include <boost/log/detail/setup_config.hpp>
|
Chris@16
|
24 #include <boost/log/sinks/sink.hpp>
|
Chris@16
|
25 #include <boost/log/utility/setup/settings.hpp>
|
Chris@16
|
26 #include <boost/log/detail/header.hpp>
|
Chris@16
|
27
|
Chris@16
|
28 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
29 #pragma once
|
Chris@16
|
30 #endif
|
Chris@16
|
31
|
Chris@16
|
32 namespace boost {
|
Chris@16
|
33
|
Chris@16
|
34 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
35
|
Chris@16
|
36 /*!
|
Chris@16
|
37 * The function initializes the logging library from a settings container
|
Chris@16
|
38 *
|
Chris@16
|
39 * \param setts Library settings container
|
Chris@16
|
40 *
|
Chris@16
|
41 * \b Throws: An <tt>std::exception</tt>-based exception if the provided settings are not valid.
|
Chris@16
|
42 */
|
Chris@16
|
43 template< typename CharT >
|
Chris@16
|
44 BOOST_LOG_SETUP_API void init_from_settings(basic_settings_section< CharT > const& setts);
|
Chris@16
|
45
|
Chris@16
|
46
|
Chris@16
|
47 /*!
|
Chris@16
|
48 * Sink factory base interface
|
Chris@16
|
49 */
|
Chris@16
|
50 template< typename CharT >
|
Chris@16
|
51 struct sink_factory
|
Chris@16
|
52 {
|
Chris@16
|
53 //! Character type
|
Chris@16
|
54 typedef CharT char_type;
|
Chris@16
|
55 //! String type
|
Chris@16
|
56 typedef std::basic_string< char_type > string_type;
|
Chris@16
|
57 //! Settings section type
|
Chris@16
|
58 typedef basic_settings_section< char_type > settings_section;
|
Chris@16
|
59
|
Chris@16
|
60 /*!
|
Chris@16
|
61 * Default constructor
|
Chris@16
|
62 */
|
Chris@16
|
63 BOOST_DEFAULTED_FUNCTION(sink_factory(), {})
|
Chris@16
|
64
|
Chris@16
|
65 /*!
|
Chris@16
|
66 * Virtual destructor
|
Chris@16
|
67 */
|
Chris@16
|
68 virtual ~sink_factory() {}
|
Chris@16
|
69
|
Chris@16
|
70 /*!
|
Chris@16
|
71 * The function creates a formatter for the specified attribute.
|
Chris@16
|
72 *
|
Chris@16
|
73 * \param settings Sink parameters
|
Chris@16
|
74 */
|
Chris@16
|
75 virtual shared_ptr< sinks::sink > create_sink(settings_section const& settings) = 0;
|
Chris@16
|
76
|
Chris@16
|
77 BOOST_DELETED_FUNCTION(sink_factory(sink_factory const&))
|
Chris@16
|
78 BOOST_DELETED_FUNCTION(sink_factory& operator= (sink_factory const&))
|
Chris@16
|
79 };
|
Chris@16
|
80
|
Chris@16
|
81 /*!
|
Chris@16
|
82 * \brief The function registers a factory for a custom sink
|
Chris@16
|
83 *
|
Chris@16
|
84 * The function registers a factory for a sink. The factory will be called to create sink
|
Chris@16
|
85 * instance when the parser discovers the specified sink type in the settings file. The
|
Chris@16
|
86 * factory must accept a map of parameters [parameter name -> parameter value] that it
|
Chris@16
|
87 * may use to initialize the sink. The factory must return a non-NULL pointer to the
|
Chris@16
|
88 * constructed sink instance.
|
Chris@16
|
89 *
|
Chris@16
|
90 * \param sink_name The custom sink name. Must point to a zero-terminated sequence of characters,
|
Chris@16
|
91 * must not be NULL.
|
Chris@16
|
92 * \param factory Pointer to the custom sink factory. Must not be NULL.
|
Chris@16
|
93 */
|
Chris@16
|
94 template< typename CharT >
|
Chris@16
|
95 BOOST_LOG_SETUP_API void register_sink_factory(const char* sink_name, shared_ptr< sink_factory< CharT > > const& factory);
|
Chris@16
|
96
|
Chris@16
|
97 /*!
|
Chris@16
|
98 * \brief The function registers a factory for a custom sink
|
Chris@16
|
99 *
|
Chris@16
|
100 * The function registers a factory for a sink. The factory will be called to create sink
|
Chris@16
|
101 * instance when the parser discovers the specified sink type in the settings file. The
|
Chris@16
|
102 * factory must accept a map of parameters [parameter name -> parameter value] that it
|
Chris@16
|
103 * may use to initialize the sink. The factory must return a non-NULL pointer to the
|
Chris@16
|
104 * constructed sink instance.
|
Chris@16
|
105 *
|
Chris@16
|
106 * \param sink_name The custom sink name
|
Chris@16
|
107 * \param factory Pointer to the custom sink factory. Must not be NULL.
|
Chris@16
|
108 */
|
Chris@16
|
109 template< typename CharT >
|
Chris@16
|
110 inline void register_sink_factory(std::string const& sink_name, shared_ptr< sink_factory< CharT > > const& factory)
|
Chris@16
|
111 {
|
Chris@16
|
112 register_sink_factory(sink_name.c_str(), factory);
|
Chris@16
|
113 }
|
Chris@16
|
114
|
Chris@16
|
115 /*!
|
Chris@16
|
116 * \brief The function registers a factory for a custom sink
|
Chris@16
|
117 *
|
Chris@16
|
118 * The function registers a factory for a sink. The factory will be called to create sink
|
Chris@16
|
119 * instance when the parser discovers the specified sink type in the settings file. The
|
Chris@16
|
120 * factory must accept a map of parameters [parameter name -> parameter value] that it
|
Chris@16
|
121 * may use to initialize the sink. The factory must return a non-NULL pointer to the
|
Chris@16
|
122 * constructed sink instance.
|
Chris@16
|
123 *
|
Chris@16
|
124 * \param sink_name The custom sink name. Must point to a zero-terminated sequence of characters,
|
Chris@16
|
125 * must not be NULL.
|
Chris@16
|
126 * \param factory Pointer to the custom sink factory. Must not be NULL.
|
Chris@16
|
127 */
|
Chris@16
|
128 template< typename FactoryT >
|
Chris@16
|
129 inline typename enable_if<
|
Chris@16
|
130 is_base_and_derived< sink_factory< typename FactoryT::char_type >, FactoryT >
|
Chris@16
|
131 >::type register_sink_factory(const char* sink_name, shared_ptr< FactoryT > const& factory)
|
Chris@16
|
132 {
|
Chris@16
|
133 typedef sink_factory< typename FactoryT::char_type > factory_base;
|
Chris@16
|
134 register_sink_factory(sink_name, boost::static_pointer_cast< factory_base >(factory));
|
Chris@16
|
135 }
|
Chris@16
|
136
|
Chris@16
|
137 /*!
|
Chris@16
|
138 * \brief The function registers a factory for a custom sink
|
Chris@16
|
139 *
|
Chris@16
|
140 * The function registers a factory for a sink. The factory will be called to create sink
|
Chris@16
|
141 * instance when the parser discovers the specified sink type in the settings file. The
|
Chris@16
|
142 * factory must accept a map of parameters [parameter name -> parameter value] that it
|
Chris@16
|
143 * may use to initialize the sink. The factory must return a non-NULL pointer to the
|
Chris@16
|
144 * constructed sink instance.
|
Chris@16
|
145 *
|
Chris@16
|
146 * \param sink_name The custom sink name
|
Chris@16
|
147 * \param factory Pointer to the custom sink factory. Must not be NULL.
|
Chris@16
|
148 */
|
Chris@16
|
149 template< typename FactoryT >
|
Chris@16
|
150 inline typename enable_if<
|
Chris@16
|
151 is_base_and_derived< sink_factory< typename FactoryT::char_type >, FactoryT >
|
Chris@16
|
152 >::type register_sink_factory(std::string const& sink_name, shared_ptr< FactoryT > const& factory)
|
Chris@16
|
153 {
|
Chris@16
|
154 typedef sink_factory< typename FactoryT::char_type > factory_base;
|
Chris@16
|
155 register_sink_factory(sink_name.c_str(), boost::static_pointer_cast< factory_base >(factory));
|
Chris@16
|
156 }
|
Chris@16
|
157
|
Chris@16
|
158 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
159
|
Chris@16
|
160 } // namespace boost
|
Chris@16
|
161
|
Chris@16
|
162 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
163
|
Chris@16
|
164 #endif // BOOST_LOG_UTILITY_SETUP_FROM_SETTINGS_HPP_INCLUDED_
|