|
||||
File indexing completed on 2025-01-18 09:39:19
0001 /* 0002 * Copyright Andrey Semashev 2007 - 2015. 0003 * Distributed under the Boost Software License, Version 1.0. 0004 * (See accompanying file LICENSE_1_0.txt or copy at 0005 * http://www.boost.org/LICENSE_1_0.txt) 0006 */ 0007 /*! 0008 * \file core/core.hpp 0009 * \author Andrey Semashev 0010 * \date 19.04.2007 0011 * 0012 * This header contains logging core class definition. 0013 */ 0014 0015 #ifndef BOOST_LOG_CORE_CORE_HPP_INCLUDED_ 0016 #define BOOST_LOG_CORE_CORE_HPP_INCLUDED_ 0017 0018 #include <utility> 0019 #include <boost/smart_ptr/shared_ptr.hpp> 0020 #include <boost/move/core.hpp> 0021 #include <boost/log/detail/config.hpp> 0022 #include <boost/log/detail/light_function.hpp> 0023 #include <boost/log/core/record.hpp> 0024 #include <boost/log/attributes/attribute_set.hpp> 0025 #include <boost/log/attributes/attribute_name.hpp> 0026 #include <boost/log/attributes/attribute.hpp> 0027 #include <boost/log/attributes/attribute_value_set.hpp> 0028 #include <boost/log/expressions/filter.hpp> 0029 #include <boost/log/detail/header.hpp> 0030 0031 #ifdef BOOST_HAS_PRAGMA_ONCE 0032 #pragma once 0033 #endif 0034 0035 namespace boost { 0036 0037 BOOST_LOG_OPEN_NAMESPACE 0038 0039 #ifndef BOOST_LOG_DOXYGEN_PASS 0040 0041 namespace sinks { 0042 0043 class sink; 0044 0045 } // namespace sinks 0046 0047 #endif // BOOST_LOG_DOXYGEN_PASS 0048 0049 class core; 0050 0051 typedef shared_ptr< core > core_ptr; 0052 0053 /*! 0054 * \brief Logging library core class 0055 * 0056 * The logging core is used to interconnect log sources and sinks. It also provides 0057 * a number of basic features, like global filtering and global and thread-specific attribute storage. 0058 * 0059 * The logging core is a singleton. Users can acquire the core instance by calling the static method <tt>get</tt>. 0060 */ 0061 class core 0062 { 0063 public: 0064 //! Exception handler function type 0065 typedef boost::log::aux::light_function< void () > exception_handler_type; 0066 0067 private: 0068 //! Implementation type 0069 struct implementation; 0070 friend struct implementation; 0071 0072 private: 0073 //! A pointer to the implementation 0074 implementation* m_impl; 0075 0076 private: 0077 //! \cond 0078 core(); 0079 //! \endcond 0080 0081 public: 0082 /*! 0083 * Destructor. Destroys the core, releases any sinks and attributes that were registered. 0084 */ 0085 ~core(); 0086 0087 /*! 0088 * \return The method returns a pointer to the logging core singleton instance. 0089 */ 0090 BOOST_LOG_API static core_ptr get(); 0091 0092 /*! 0093 * The method enables or disables logging. 0094 * 0095 * Setting this status to \c false allows you to completely wipe out any logging activity, including 0096 * filtering and generation of attribute values. It is useful if you want to completely disable logging 0097 * in a running application. The state of logging does not alter any other properties of the logging 0098 * library, such as filters or sinks, so you can enable logging with the very same settings that you had 0099 * when the logging was disabled. 0100 * This feature may also be useful if you want to perform major changes to logging configuration and 0101 * don't want your application to block on opening or pushing a log record. 0102 * 0103 * By default logging is enabled. 0104 * 0105 * \param enabled The actual flag of logging activity. 0106 * \return The previous value of enabled/disabled logging flag 0107 */ 0108 BOOST_LOG_API bool set_logging_enabled(bool enabled = true); 0109 /*! 0110 * The method allows to detect if logging is enabled. See the comment for \c set_logging_enabled. 0111 */ 0112 BOOST_LOG_API bool get_logging_enabled() const; 0113 0114 /*! 0115 * The method sets the global logging filter. The filter is applied to every log record that is processed. 0116 * 0117 * \param filter The filter function object to be installed. 0118 */ 0119 BOOST_LOG_API void set_filter(filter const& filter); 0120 /*! 0121 * The method removes the global logging filter. All log records are passed to sinks without global filtering applied. 0122 */ 0123 BOOST_LOG_API void reset_filter(); 0124 0125 /*! 0126 * The method adds a new sink. The sink is included into logging process immediately after being added and until being removed. 0127 * No sink can be added more than once at the same time. If the sink is already registered, the call is ignored. 0128 * 0129 * \param s The sink to be registered. 0130 */ 0131 BOOST_LOG_API void add_sink(shared_ptr< sinks::sink > const& s); 0132 /*! 0133 * The method removes the sink from the output. The sink will not receive any log records after removal. 0134 * The call has no effect if the sink is not registered. 0135 * 0136 * \param s The sink to be unregistered. 0137 */ 0138 BOOST_LOG_API void remove_sink(shared_ptr< sinks::sink > const& s); 0139 /*! 0140 * The method removes all registered sinks from the output. The sinks will not receive any log records after removal. 0141 */ 0142 BOOST_LOG_API void remove_all_sinks(); 0143 0144 /*! 0145 * The method performs flush on all registered sinks. 0146 * 0147 * \note This method may take long time to complete as it may block until all sinks manage to process all buffered log records. 0148 * The call will also block all logging attempts until the operation completes. 0149 */ 0150 BOOST_LOG_API void flush(); 0151 0152 /*! 0153 * The method adds an attribute to the global attribute set. The attribute will be implicitly added to every log record. 0154 * 0155 * \param name The attribute name. 0156 * \param attr The attribute factory. 0157 * \return A pair of values. If the second member is \c true, then the attribute is added and the first member points to the 0158 * attribute. Otherwise the attribute was not added and the first member points to the attribute that prevents 0159 * addition. 0160 */ 0161 BOOST_LOG_API std::pair< attribute_set::iterator, bool > add_global_attribute(attribute_name const& name, attribute const& attr); 0162 /*! 0163 * The method removes an attribute from the global attribute set. 0164 * 0165 * \pre The attribute was added with the \c add_global_attribute call. 0166 * \post The attribute is no longer registered as a global attribute. The iterator is invalidated after removal. 0167 * 0168 * \param it Iterator to the previously added attribute. 0169 */ 0170 BOOST_LOG_API void remove_global_attribute(attribute_set::iterator it); 0171 0172 /*! 0173 * The method returns a copy of the complete set of currently registered global attributes. 0174 */ 0175 BOOST_LOG_API attribute_set get_global_attributes() const; 0176 /*! 0177 * The method replaces the complete set of currently registered global attributes with the provided set. 0178 * 0179 * \note The method invalidates all iterators and references that may have been returned 0180 * from the \c add_global_attribute method. 0181 * 0182 * \param attrs The set of attributes to be installed. 0183 */ 0184 BOOST_LOG_API void set_global_attributes(attribute_set const& attrs); 0185 0186 /*! 0187 * The method adds an attribute to the thread-specific attribute set. The attribute will be implicitly added to 0188 * every log record made in the current thread. 0189 * 0190 * \note In single-threaded build the effect is the same as adding the attribute globally. This, however, does 0191 * not imply that iterators to thread-specific and global attributes are interchangeable. 0192 * 0193 * \param name The attribute name. 0194 * \param attr The attribute factory. 0195 * \return A pair of values. If the second member is \c true, then the attribute is added and the first member points to the 0196 * attribute. Otherwise the attribute was not added and the first member points to the attribute that prevents 0197 * addition. 0198 */ 0199 BOOST_LOG_API std::pair< attribute_set::iterator, bool > add_thread_attribute(attribute_name const& name, attribute const& attr); 0200 /*! 0201 * The method removes an attribute from the thread-specific attribute set. 0202 * 0203 * \pre The attribute was added with the \c add_thread_attribute call. 0204 * \post The attribute is no longer registered as a thread-specific attribute. The iterator is invalidated after removal. 0205 * 0206 * \param it Iterator to the previously added attribute. 0207 */ 0208 BOOST_LOG_API void remove_thread_attribute(attribute_set::iterator it); 0209 0210 /*! 0211 * The method returns a copy of the complete set of currently registered thread-specific attributes. 0212 */ 0213 BOOST_LOG_API attribute_set get_thread_attributes() const; 0214 /*! 0215 * The method replaces the complete set of currently registered thread-specific attributes with the provided set. 0216 * 0217 * \note The method invalidates all iterators and references that may have been returned 0218 * from the \c add_thread_attribute method. 0219 * 0220 * \param attrs The set of attributes to be installed. 0221 */ 0222 BOOST_LOG_API void set_thread_attributes(attribute_set const& attrs); 0223 0224 /*! 0225 * The method sets exception handler function. The function will be called with no arguments 0226 * in case if an exception occurs during either \c open_record or \c push_record method 0227 * execution. Since exception handler is called from a \c catch statement, the exception 0228 * can be rethrown in order to determine its type. 0229 * 0230 * By default no handler is installed, thus any exception is propagated as usual. 0231 * 0232 * \sa See also: <tt>utility/exception_handler.hpp</tt> 0233 * \param handler Exception handling function 0234 * 0235 * \note The exception handler can be invoked in several threads concurrently. 0236 * Thread interruptions are not affected by exception handlers. 0237 */ 0238 BOOST_LOG_API void set_exception_handler(exception_handler_type const& handler); 0239 0240 /*! 0241 * The method attempts to open a new record to be written. While attempting to open a log record all filtering is applied. 0242 * A successfully opened record can be pushed further to sinks by calling the \c push_record method or simply destroyed by 0243 * destroying the returned object. 0244 * 0245 * More than one open records are allowed, such records exist independently. All attribute values are acquired during opening 0246 * the record and do not interact between records. 0247 * 0248 * The returned records can be copied, however, they must not be passed between different threads. 0249 * 0250 * \param source_attributes The set of source-specific attributes to be attached to the record to be opened. 0251 * \return A valid log record if the record is opened, an invalid record object if not (e.g. because it didn't pass filtering). 0252 * 0253 * \b Throws: If an exception handler is installed, only throws if the handler throws. Otherwise may 0254 * throw if one of the sinks throws, or some system resource limitation is reached. 0255 */ 0256 BOOST_LOG_API record open_record(attribute_set const& source_attributes); 0257 /*! 0258 * The method attempts to open a new record to be written. While attempting to open a log record all filtering is applied. 0259 * A successfully opened record can be pushed further to sinks by calling the \c push_record method or simply destroyed by 0260 * destroying the returned object. 0261 * 0262 * More than one open records are allowed, such records exist independently. All attribute values are acquired during opening 0263 * the record and do not interact between records. 0264 * 0265 * The returned records can be copied, however, they must not be passed between different threads. 0266 * 0267 * \param source_attributes The set of source-specific attribute values to be attached to the record to be opened. 0268 * \return A valid log record if the record is opened, an invalid record object if not (e.g. because it didn't pass filtering). 0269 * 0270 * \b Throws: If an exception handler is installed, only throws if the handler throws. Otherwise may 0271 * throw if one of the sinks throws, or some system resource limitation is reached. 0272 */ 0273 BOOST_LOG_API record open_record(attribute_value_set const& source_attributes); 0274 /*! 0275 * The method attempts to open a new record to be written. While attempting to open a log record all filtering is applied. 0276 * A successfully opened record can be pushed further to sinks by calling the \c push_record method or simply destroyed by 0277 * destroying the returned object. 0278 * 0279 * More than one open records are allowed, such records exist independently. All attribute values are acquired during opening 0280 * the record and do not interact between records. 0281 * 0282 * The returned records can be copied, however, they must not be passed between different threads. 0283 * 0284 * \param source_attributes The set of source-specific attribute values to be attached to the record to be opened. The contents 0285 * of this container are unspecified after this call. 0286 * \return A valid log record if the record is opened, an invalid record object if not (e.g. because it didn't pass filtering). 0287 * 0288 * \b Throws: If an exception handler is installed, only throws if the handler throws. Otherwise may 0289 * throw if one of the sinks throws, or some system resource limitation is reached. 0290 */ 0291 BOOST_FORCEINLINE record open_record(BOOST_RV_REF(attribute_value_set) source_attributes) 0292 { 0293 return open_record_move(static_cast< attribute_value_set& >(source_attributes)); 0294 } 0295 0296 /*! 0297 * The method pushes the record to sinks. The record is moved from in the process. 0298 * 0299 * \pre <tt>!!rec == true</tt> 0300 * \post <tt>!rec == true</tt> 0301 * \param rec A previously successfully opened log record. 0302 * 0303 * \b Throws: If an exception handler is installed, only throws if the handler throws. Otherwise may 0304 * throw if one of the sinks throws. 0305 */ 0306 BOOST_FORCEINLINE void push_record(BOOST_RV_REF(record) rec) 0307 { 0308 push_record_move(static_cast< record& >(rec)); 0309 } 0310 0311 BOOST_DELETED_FUNCTION(core(core const&)) 0312 BOOST_DELETED_FUNCTION(core& operator= (core const&)) 0313 0314 #ifndef BOOST_LOG_DOXYGEN_PASS 0315 private: 0316 //! Opens log record. This function is mostly needed to maintain ABI stable between C++03 and C++11. 0317 BOOST_LOG_API record open_record_move(attribute_value_set& source_attributes); 0318 //! The method pushes the record to sinks. 0319 BOOST_LOG_API void push_record_move(record& rec); 0320 #endif // BOOST_LOG_DOXYGEN_PASS 0321 }; 0322 0323 BOOST_LOG_CLOSE_NAMESPACE // namespace log 0324 0325 } // namespace boost 0326 0327 #include <boost/log/detail/footer.hpp> 0328 0329 #endif // BOOST_LOG_CORE_CORE_HPP_INCLUDED_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |