Class LogSink (2.20.0-rc)

A sink to receive log records.

Constructors

LogSink()

Functions

empty() const

Return true if this object has no backends.

We want to avoid synchronization overhead when checking if a log message is enabled. Most of the time, most messages will be disabled, so incurring the locking overhead on each message would be too expensive and would discourage developers from creating logs. Furthermore, missing a few messages while the change of state "propagates" to other threads does not affect the correctness of the program.

Note that memory_order_relaxed does not provide a compiler barrier either, so in theory stores into the atomic could be reordered by the optimizer. We have no reason to worry about that because all the writes are done inside a critical section protected by a mutex. The compiler cannot (or should not) reorder operations around those.

Returns
TypeDescription
bool

is_enabled(Severity) const

Return true if severity is enabled.

We want to avoid synchronization overhead when checking if a log message is enabled. Most of the time, most messages will be disabled, so incurring the locking overhead on each message would be too expensive and would discourage developers from creating logs. Furthermore, missing a few messages while the change of state "propagates" to other threads does not affect the correctness of the program.

Note that memory_order_relaxed does not provide a compiler barrier either, so in theory stores into the atomic could be reordered by the optimizer. We have no reason to worry about that because all the writes are done inside a critical section protected by a mutex. The compiler cannot (or should not) reorder operations around those.

Parameter
NameDescription
severity Severity
Returns
TypeDescription
bool

set_minimum_severity(Severity)

Parameter
NameDescription
minimum Severity
Returns
TypeDescription
void

minimum_severity() const

Returns
TypeDescription
Severity

AddBackend(std::shared_ptr< LogBackend >)

Parameter
NameDescription
backend std::shared_ptr< LogBackend >
Returns
TypeDescription
BackendId

RemoveBackend(BackendId)

Parameter
NameDescription
id BackendId
Returns