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 thatmemory_order_relaxeddoes 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 ifseverityis 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 thatmemory_order_relaxeddoes 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-09-04 UTC."],[[["\u003cp\u003eThis document outlines the \u003ccode\u003eLogSink\u003c/code\u003e class, a component designed to receive and manage log records, and includes a list of available versions, the latest being \u003ccode\u003e2.37.0-rc\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eLogSink\u003c/code\u003e class provides functions to manage log backends, including adding, removing, and clearing them, along with methods to determine if the object has backends and their quantity.\u003c/p\u003e\n"],["\u003cp\u003eCore functionalities of \u003ccode\u003eLogSink\u003c/code\u003e include methods for setting the minimum severity level for logs, checking if a particular severity is enabled, and flushing all backends.\u003c/p\u003e\n"],["\u003cp\u003eThe class also allows managing \u003ccode\u003estd::clog\u003c/code\u003e through \u003ccode\u003eEnableStdClog\u003c/code\u003e and \u003ccode\u003eDisableStdClog\u003c/code\u003e, with a static method to access the singleton instance of the \u003ccode\u003eLogSink\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe document details various methods related to logging, such as \u003ccode\u003eLog\u003c/code\u003e for recording a log entry and \u003ccode\u003eCompileTimeEnabled\u003c/code\u003e for checking severity at compile time, all within the context of the provided version links.\u003c/p\u003e\n"]]],[],null,["# Class LogSink (2.16.0)\n\nVersion 2.16.0keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1LogSink)\n- [2.41.0](/cpp/docs/reference/common/2.41.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.40.0](/cpp/docs/reference/common/2.40.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.39.0](/cpp/docs/reference/common/2.39.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.38.0](/cpp/docs/reference/common/2.38.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.37.0](/cpp/docs/reference/common/2.37.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.36.0](/cpp/docs/reference/common/2.36.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.35.0](/cpp/docs/reference/common/2.35.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.34.0](/cpp/docs/reference/common/2.34.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.33.0](/cpp/docs/reference/common/2.33.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.32.0](/cpp/docs/reference/common/2.32.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.31.0](/cpp/docs/reference/common/2.31.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.30.0](/cpp/docs/reference/common/2.30.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.29.0](/cpp/docs/reference/common/2.29.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.28.0](/cpp/docs/reference/common/2.28.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.27.0](/cpp/docs/reference/common/2.27.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.26.0](/cpp/docs/reference/common/2.26.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.25.1](/cpp/docs/reference/common/2.25.1/classgoogle_1_1cloud_1_1LogSink)\n- [2.24.0](/cpp/docs/reference/common/2.24.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.23.0](/cpp/docs/reference/common/2.23.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.22.1](/cpp/docs/reference/common/2.22.1/classgoogle_1_1cloud_1_1LogSink)\n- [2.21.0](/cpp/docs/reference/common/2.21.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.20.0](/cpp/docs/reference/common/2.20.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.19.0](/cpp/docs/reference/common/2.19.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.18.0](/cpp/docs/reference/common/2.18.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.17.0](/cpp/docs/reference/common/2.17.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.16.0](/cpp/docs/reference/common/2.16.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.15.1](/cpp/docs/reference/common/2.15.1/classgoogle_1_1cloud_1_1LogSink)\n- [2.14.0](/cpp/docs/reference/common/2.14.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.13.0](/cpp/docs/reference/common/2.13.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.12.0](/cpp/docs/reference/common/2.12.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.11.0](/cpp/docs/reference/common/2.11.0/classgoogle_1_1cloud_1_1LogSink)\n- [2.10.1](/cpp/docs/reference/common/2.10.1/classgoogle_1_1cloud_1_1LogSink) \nA sink to receive log records.\n\nConstructors\n------------\n\n### LogSink()\n\nFunctions\n---------\n\n### empty() const\n\nReturn true if this object has no backends. \nWe 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.\n\nNote 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.\n\n### is_enabled(Severity) const\n\nReturn true if `severity` is enabled. \nWe 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.\n\nNote 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.\n\n### set_minimum_severity(Severity)\n\n### minimum_severity() const\n\n### AddBackend(std::shared_ptr\\\u003c LogBackend \\\u003e)\n\n### RemoveBackend(BackendId)\n\n### ClearBackends()\n\n### BackendCount() const\n\n### Log(LogRecord)\n\n### Flush()\n\nFlush all the current backends.\n\n### static CompileTimeEnabled(Severity)\n\nReturn true if the severity is enabled at compile time.\n\n### static Instance()\n\nReturn the singleton instance for this application.\n\n### static EnableStdClog(Severity)\n\nEnable `std::clog` on [`LogSink::Instance()`](/cpp/docs/reference/common/2.16.0/classgoogle_1_1cloud_1_1LogSink#classgoogle_1_1cloud_1_1LogSink_1a06247b1adf1203876402ba6a9be76a7e). \nThis is also enabled if the \"GOOGLE_CLOUD_CPP_ENABLE_CLOG\" environment variable is set.\n\n### static DisableStdClog()\n\nDisable `std::clog` on [`LogSink::Instance()`](/cpp/docs/reference/common/2.16.0/classgoogle_1_1cloud_1_1LogSink#classgoogle_1_1cloud_1_1LogSink_1a06247b1adf1203876402ba6a9be76a7e). \nNote that this will remove the default logging backend.\n\nType Aliases\n------------\n\n### BackendId\n\n**Alias Of** : `long`"]]