Logging library core class. More...
#include <core.hpp>
Public Types | |
typedef std::type_info | typeinfo |
typedef boost::log::aux::light_function < void() > | exception_handler_type |
Exception handler function type. More... | |
Public Member Functions | |
~core () | |
Destructor. More... | |
BOOST_LOG_API bool | set_logging_enabled (bool enabled=true) |
The method enables or disables logging. More... | |
BOOST_LOG_API bool | get_logging_enabled () const |
The method allows to detect if logging is enabled. More... | |
BOOST_LOG_API void | set_filter (filter const &filter) |
The method sets the global logging filter. More... | |
BOOST_LOG_API void | reset_filter () |
The method removes the global logging filter. More... | |
BOOST_LOG_API void | add_sink (shared_ptr< sinks::sink > const &s) |
The method adds a new sink. More... | |
BOOST_LOG_API void | remove_sink (shared_ptr< sinks::sink > const &s) |
The method removes the sink from the output. More... | |
BOOST_LOG_API void | remove_all_sinks () |
The method removes all registered sinks from the output. More... | |
BOOST_LOG_API void | flush () |
The method performs flush on all registered sinks. More... | |
BOOST_LOG_API std::pair < attribute_set::iterator, bool > | add_global_attribute (attribute_name const &name, attribute const &attr) |
The method adds an attribute to the global attribute set. More... | |
BOOST_LOG_API void | remove_global_attribute (attribute_set::iterator it) |
The method removes an attribute from the global attribute set. More... | |
BOOST_LOG_API attribute_set | get_global_attributes () const |
The method returns a copy of the complete set of currently registered global attributes. More... | |
BOOST_LOG_API void | set_global_attributes (attribute_set const &attrs) |
The method replaces the complete set of currently registered global attributes with the provided set. More... | |
BOOST_LOG_API std::pair < attribute_set::iterator, bool > | add_thread_attribute (attribute_name const &name, attribute const &attr) |
The method adds an attribute to the thread-specific attribute set. More... | |
BOOST_LOG_API void | remove_thread_attribute (attribute_set::iterator it) |
The method removes an attribute from the thread-specific attribute set. More... | |
BOOST_LOG_API attribute_set | get_thread_attributes () const |
The method returns a copy of the complete set of currently registered thread-specific attributes. More... | |
BOOST_LOG_API void | set_thread_attributes (attribute_set const &attrs) |
The method replaces the complete set of currently registered thread-specific attributes with the provided set. More... | |
BOOST_LOG_API void | set_exception_handler (exception_handler_type const &handler) |
The method sets exception handler function. More... | |
BOOST_LOG_API record | open_record (attribute_set const &source_attributes) |
The method attempts to open a new record to be written. More... | |
BOOST_LOG_API record | open_record (attribute_value_set const &source_attributes) |
The method attempts to open a new record to be written. More... | |
BOOST_FORCEINLINE record | open_record (BOOST_RV_REF(attribute_value_set) source_attributes) |
The method attempts to open a new record to be written. More... | |
BOOST_FORCEINLINE void | push_record (BOOST_RV_REF(record) rec) |
The method pushes the record to sinks. More... | |
Static Public Member Functions | |
static BOOST_LOG_API core_ptr | get () |
Friends | |
struct | implementation |
Logging library core class.
The logging core is used to interconnect log sources and sinks. It also provides a number of basic features, like global filtering and global and thread-specific attribute storage.
The logging core is a singleton. Users can acquire the core instance by calling the static method get
.
typedef boost::log::aux::light_function< void () > boost::core::exception_handler_type |
Exception handler function type.
typedef std::type_info boost::core::typeinfo |
boost::core::~core | ( | ) |
Destructor.
Destroys the core, releases any sinks and attributes that were registered.
BOOST_LOG_API std::pair< attribute_set::iterator, bool > boost::core::add_global_attribute | ( | attribute_name const & | name, |
attribute const & | attr | ||
) |
The method adds an attribute to the global attribute set.
The attribute will be implicitly added to every log record.
name | The attribute name. |
attr | The attribute factory. |
true
, then the attribute is added and the first member points to the attribute. Otherwise the attribute was not added and the first member points to the attribute that prevents addition. BOOST_LOG_API void boost::core::add_sink | ( | shared_ptr< sinks::sink > const & | s | ) |
The method adds a new sink.
The sink is included into logging process immediately after being added and until being removed. No sink can be added more than once at the same time. If the sink is already registered, the call is ignored.
s | The sink to be registered. |
BOOST_LOG_API std::pair< attribute_set::iterator, bool > boost::core::add_thread_attribute | ( | attribute_name const & | name, |
attribute const & | attr | ||
) |
The method adds an attribute to the thread-specific attribute set.
The attribute will be implicitly added to every log record made in the current thread.
name | The attribute name. |
attr | The attribute factory. |
true
, then the attribute is added and the first member points to the attribute. Otherwise the attribute was not added and the first member points to the attribute that prevents addition. BOOST_LOG_API void boost::core::flush | ( | ) |
The method performs flush on all registered sinks.
|
static |
Referenced by boost::add_common_attributes(), boost::aux::add_console_log(), and boost::aux::add_file_log().
BOOST_LOG_API attribute_set boost::core::get_global_attributes | ( | ) | const |
The method returns a copy of the complete set of currently registered global attributes.
BOOST_LOG_API bool boost::core::get_logging_enabled | ( | ) | const |
The method allows to detect if logging is enabled.
See the comment for set_logging_enabled
.
BOOST_LOG_API attribute_set boost::core::get_thread_attributes | ( | ) | const |
The method returns a copy of the complete set of currently registered thread-specific attributes.
BOOST_LOG_API record boost::core::open_record | ( | attribute_set const & | source_attributes | ) |
The method attempts to open a new record to be written.
While attempting to open a log record all filtering is applied. A successfully opened record can be pushed further to sinks by calling the push_record
method or simply destroyed by destroying the returned object.
More than one open records are allowed, such records exist independently. All attribute values are acquired during opening the record and do not interact between records.
The returned records can be copied, however, they must not be passed between different threads.
source_attributes | The set of source-specific attributes to be attached to the record to be opened. |
Throws: If an exception handler is installed, only throws if the handler throws. Otherwise may throw if one of the sinks throws, or some system resource limitation is reached.
BOOST_LOG_API record boost::core::open_record | ( | attribute_value_set const & | source_attributes | ) |
The method attempts to open a new record to be written.
While attempting to open a log record all filtering is applied. A successfully opened record can be pushed further to sinks by calling the push_record
method or simply destroyed by destroying the returned object.
More than one open records are allowed, such records exist independently. All attribute values are acquired during opening the record and do not interact between records.
The returned records can be copied, however, they must not be passed between different threads.
source_attributes | The set of source-specific attribute values to be attached to the record to be opened. |
Throws: If an exception handler is installed, only throws if the handler throws. Otherwise may throw if one of the sinks throws, or some system resource limitation is reached.
|
inline |
The method attempts to open a new record to be written.
While attempting to open a log record all filtering is applied. A successfully opened record can be pushed further to sinks by calling the push_record
method or simply destroyed by destroying the returned object.
More than one open records are allowed, such records exist independently. All attribute values are acquired during opening the record and do not interact between records.
The returned records can be copied, however, they must not be passed between different threads.
source_attributes | The set of source-specific attribute values to be attached to the record to be opened. The contents of this container are unspecified after this call. |
Throws: If an exception handler is installed, only throws if the handler throws. Otherwise may throw if one of the sinks throws, or some system resource limitation is reached.
|
inline |
The method pushes the record to sinks.
The record is moved from in the process.
!!rec == true
!rec == true
rec | A previously successfully opened log record. |
Throws: If an exception handler is installed, only throws if the handler throws. Otherwise may throw if one of the sinks throws.
BOOST_LOG_API void boost::core::remove_all_sinks | ( | ) |
The method removes all registered sinks from the output.
The sinks will not receive any log records after removal.
BOOST_LOG_API void boost::core::remove_global_attribute | ( | attribute_set::iterator | it | ) |
The method removes an attribute from the global attribute set.
add_global_attribute
call. it | Iterator to the previously added attribute. |
BOOST_LOG_API void boost::core::remove_sink | ( | shared_ptr< sinks::sink > const & | s | ) |
The method removes the sink from the output.
The sink will not receive any log records after removal. The call has no effect if the sink is not registered.
s | The sink to be unregistered. |
BOOST_LOG_API void boost::core::remove_thread_attribute | ( | attribute_set::iterator | it | ) |
The method removes an attribute from the thread-specific attribute set.
add_thread_attribute
call. it | Iterator to the previously added attribute. |
BOOST_LOG_API void boost::core::reset_filter | ( | ) |
The method removes the global logging filter.
All log records are passed to sinks without global filtering applied.
BOOST_LOG_API void boost::core::set_exception_handler | ( | exception_handler_type const & | handler | ) |
The method sets exception handler function.
The function will be called with no arguments in case if an exception occurs during either open_record
or push_record
method execution. Since exception handler is called from a catch
statement, the exception can be rethrown in order to determine its type.
By default no handler is installed, thus any exception is propagated as usual.
utility/exception_handler.hpp
handler | Exception handling function |
BOOST_LOG_API void boost::core::set_filter | ( | filter const & | filter | ) |
The method sets the global logging filter.
The filter is applied to every log record that is processed.
filter | The filter function object to be installed. |
BOOST_LOG_API void boost::core::set_global_attributes | ( | attribute_set const & | attrs | ) |
The method replaces the complete set of currently registered global attributes with the provided set.
add_global_attribute
method.attrs | The set of attributes to be installed. |
BOOST_LOG_API bool boost::core::set_logging_enabled | ( | bool | enabled = true | ) |
The method enables or disables logging.
Setting this status to false
allows you to completely wipe out any logging activity, including filtering and generation of attribute values. It is useful if you want to completely disable logging in a running application. The state of logging does not alter any other properties of the logging library, such as filters or sinks, so you can enable logging with the very same settings that you had when the logging was disabled. This feature may also be useful if you want to perform major changes to logging configuration and don't want your application to block on opening or pushing a log record.
By default logging is enabled.
enabled | The actual flag of logging activity. |
BOOST_LOG_API void boost::core::set_thread_attributes | ( | attribute_set const & | attrs | ) |
The method replaces the complete set of currently registered thread-specific attributes with the provided set.
add_thread_attribute
method.attrs | The set of attributes to be installed. |
|
friend |