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
Type
Description
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
Name
Description
severity
Severity
Returns
Type
Description
bool
set_minimum_severity(Severity)
Parameter
Name
Description
minimum
Severity
Returns
Type
Description
void
minimum_severity() const
Returns
Type
Description
Severity
AddBackend(std::shared_ptr< LogBackend >)
Parameter
Name
Description
backend
std::shared_ptr< LogBackend >
Returns
Type
Description
BackendId
RemoveBackend(BackendId)
Parameter
Name
Description
id
BackendId
Returns
Type
Description
void
ClearBackends()
Returns
Type
Description
void
BackendCount() const
Returns
Type
Description
std::size_t
Log(LogRecord)
Parameter
Name
Description
log_record
LogRecord
Returns
Type
Description
void
Flush()
Flush all the current backends.
Returns
Type
Description
void
static CompileTimeEnabled(Severity)
Return true if the severity is enabled at compile time.
Parameter
Name
Description
level
Severity
Returns
Type
Description
bool constexpr
static Instance()
Return the singleton instance for this application.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-03-05 UTC."],[[["This document provides comprehensive information on the `LogSink` class, specifically related to version 2.24.0 and other versions of the C++ client library."],["`LogSink` is designed to receive log records, with functionalities to manage log backends, set minimum severity levels, and check if specific severities are enabled."],["The class includes static methods to handle a singleton instance, enable or disable `std::clog`, and to check compile-time severity levels."],["The latest version available in the document is 2.37.0-rc, alongside older versions ranging from 2.36.0 down to 2.10.1."],["The document contains links to different versions of the `LogSink` class for users who need to reference different versions."]]],[]]