# Core components

Andrey Semashev

19.04.2007

This header contains logging core class definition. 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`.

Exception handler function type. unspecified bool `booltrue

The actual flag of logging activity.

`

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.

The previous value of enabled/disabled logging flag

bool

The method allows to detect if logging is enabled. See the comment for `set_logging_enabled`.

void `filter const &

The filter function object to be installed.

`

The method sets the global logging filter. The filter is applied to every log record that is processed.

void

The method removes the global logging filter. All log records are passed to sinks without global filtering applied.

void `shared_ptr< sinks::sink > const &

The sink to be registered.

`

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.

void `shared_ptr< sinks::sink > const &

The sink to be unregistered.

`

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.

void

The method removes all registered sinks from the output. The sinks will not receive any log records after removal.

void

The method performs flush on all registered sinks.

This method may take long time to complete as it may block until all sinks manage to process all buffered log records. The call will also block all logging attempts until the operation completes.

std::pair< attribute_set::iterator, bool >`attribute_name const &

The attribute name.

``attribute const &

The attribute factory.

`

The method adds an attribute to the global attribute set. The attribute will be implicitly added to every log record.

A pair of values. If the second member is `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.

void `attribute_set::iterator

Iterator to the previously added attribute.

`

The method removes an attribute from the global attribute set.

The attribute was added with the `add_global_attribute` call.

The attribute is no longer registered as a global attribute. The iterator is invalidated after removal.

attribute_set

The method returns a copy of the complete set of currently registered global attributes.

void `attribute_set const &

The set of attributes to be installed.

`

The method replaces the complete set of currently registered global attributes with the provided set.

The method invalidates all iterators and references that may have been returned from the `add_global_attribute` method.

std::pair< attribute_set::iterator, bool >`attribute_name const &

The attribute name.

``attribute const &

The attribute factory.

`

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.

In single-threaded build the effect is the same as adding the attribute globally. This, however, does not imply that iterators to thread-specific and global attributes are interchangeable.

A pair of values. If the second member is `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.

void `attribute_set::iterator

Iterator to the previously added attribute.

`

The method removes an attribute from the thread-specific attribute set.

The attribute was added with the `add_thread_attribute` call.

The attribute is no longer registered as a thread-specific attribute. The iterator is invalidated after removal.

attribute_set

The method returns a copy of the complete set of currently registered thread-specific attributes.

void `attribute_set const &

The set of attributes to be installed.

`

The method replaces the complete set of currently registered thread-specific attributes with the provided set.

The method invalidates all iterators and references that may have been returned from the `add_thread_attribute` method.

void `exception_handler_type const &

Exception handling function

`

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.

See Also:

See also: `utility/exception_handler.hpp`

The exception handler can be invoked in several threads concurrently. Thread interruptions are not affected by exception handlers.

`record` `attribute_set const &

The set of source-specific attributes to be attached to the record to be opened.

`

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.

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.

A valid log record if the record is opened, an invalid record object if not (e.g. because it didn't pass filtering).

`record` `attribute_value_set const &

The set of source-specific attribute values to be attached to the record to be opened.

`

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.

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.

A valid log record if the record is opened, an invalid record object if not (e.g. because it didn't pass filtering).

`record` `attribute_value_set &&

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.

`

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.

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.

A valid log record if the record is opened, an invalid record object if not (e.g. because it didn't pass filtering).

void``record` &&

A previously successfully opened log record.

`

The method pushes the record to sinks. The record is moved from in the process.

Throws: If an exception handler is installed, only throws if the handler throws. Otherwise may throw if one of the sinks throws.

`!!rec == true`

`!rec == true`

Destructor. Destroys the core, releases any sinks and attributes that were registered.

``core` const &` `core` &``core` const &` core_ptr

The method returns a pointer to the logging core singleton instance.

shared_ptr< `core` >

Andrey Semashev

09.03.2009

This header contains a logging record class definition. Logging record class.

The logging record encapsulates all information related to a single logging statement, in particular, attribute values view and the log message string. The record can be updated before pushing for further processing to the logging core.

attribute_value_set &

`!!*this`

A reference to the set of attribute values attached to this record

attribute_value_set const &

`!!*this`

A reference to the set of attribute values attached to this record

bool

Conversion to an unspecified boolean type

`true`, if the `*this` identifies a log record, `false`, if the `*this` is not valid

bool

Inverted conversion to an unspecified boolean type

`false`, if the `*this` identifies a log record, `true`, if the `*this` is not valid

void``record` &

Another record to swap with Throws: Nothing

`

Swaps two handles

void

Resets the log record handle. If there are no other handles left, the log record is closed and all resources referenced by the record are released.

`!*this == true`

attribute_value_set::mapped_type `attribute_value_set::key_type

Attribute name.

`

Attribute value lookup.

An `attribute_value`, non-empty if it is found, empty otherwise.

result_of::extract< typename expressions::attribute_keyword< DescriptorT, ActorT >::value_type, DescriptorT >::type template< typename > class `expressions::attribute_keyword< DescriptorT, ActorT > const &

Attribute keyword.

`

Attribute value lookup.

A `value_ref` with extracted attribute value if it is found, empty `value_ref` otherwise.

`record_view`

The function ensures that the log record does not depend on any thread-specific data. Then the record contents are used to construct a ``record_view`` which is returned from the function. The record is no longer valid after the call.

`!!*this`

`!*this`

The record view that contains all attribute values from the original record.

Default constructor. Creates an empty record that is equivalent to the invalid record handle.

`!*this == true`

``record` &&`

Move constructor. Source record contents unspecified after the operation.

Destructor. Destroys the record, releases any sinks and attribute values that were involved in processing this record.

`record` &``record` &&`

Move assignment. Source record contents unspecified after the operation.

`void``record` &```record` &`

A free-standing swap function overload for `record`

`

Andrey Semashev

09.03.2009

This header contains a logging record view class definition. Logging record view class.

The logging record encapsulates all information related to a single logging statement, in particular, attribute values view and the log message string. The view is immutable, it is implemented as a wrapper around a reference-counted implementation.

attribute_value_set const &

`!!*this`

A reference to the set of attribute values attached to this record

bool``record_view` const &

Comparand

`

Equality comparison

`true` if both `*this` and that identify the same log record or both do not identify any record, `false` otherwise.

bool``record_view` const &

Comparand

`

Inequality comparison

`!(*this == that)`

bool

Conversion to an unspecified boolean type

`true`, if the `*this` identifies a log record, `false`, if the `*this` is not valid

bool

Inverted conversion to an unspecified boolean type

`false`, if the `*this` identifies a log record, `true`, if the `*this` is not valid

void``record_view` &

Another record to swap with Throws: Nothing

`

Swaps two handles

void

Resets the log record handle. If there are no other handles left, the log record is closed and all resources referenced by the record are released.

`!*this == true`

attribute_value_set::mapped_type `attribute_value_set::key_type

Attribute name.

`

Attribute value lookup.

An `attribute_value`, non-empty if it is found, empty otherwise.

result_of::extract< typename expressions::attribute_keyword< DescriptorT, ActorT >::value_type, DescriptorT >::type template< typename > class `expressions::attribute_keyword< DescriptorT, ActorT > const &

Attribute keyword.

`

Attribute value lookup.

A `value_ref` with extracted attribute value if it is found, empty `value_ref` otherwise.

Default constructor. Creates an empty record view that is equivalent to the invalid record handle.

`!*this == true`

``record_view` const &`

Copy constructor

``record_view` &&`

Move constructor. Source record contents unspecified after the operation.

Destructor. Destroys the record, releases any sinks and attribute values that were involved in processing this record.

`record_view` &``record_view` const &`

Copy assignment

`record_view` &``record_view` &&`

Move assignment. Source record contents unspecified after the operation.

`void``record_view` &```record_view` &`

A free-standing swap function overload for ``record_view``

`