Class LogSink (2.46.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 thatmemory_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 ifseverity 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 thatmemory_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
severitySeverity
Returns
TypeDescription
bool

set_minimum_severity(Severity)

Parameter
NameDescription
minimumSeverity
Returns
TypeDescription
void

minimum_severity() const

Returns
TypeDescription
Severity

AddBackend(std::shared_ptr< LogBackend >)

Parameter
NameDescription
backendstd::shared_ptr< LogBackend >
Returns
TypeDescription
BackendId

RemoveBackend(BackendId)

Parameter
NameDescription
idBackendId
Returns
TypeDescription
void

ClearBackends()

Returns
TypeDescription
void

BackendCount() const

Returns
TypeDescription
std::size_t

Log(LogRecord)

Parameter
NameDescription
log_recordLogRecord
Returns
TypeDescription
void

Flush()

Flush all the current backends.

Returns
TypeDescription
void

static CompileTimeEnabled(Severity)

Return true if the severity is enabled at compile time.

Parameter
NameDescription
levelSeverity
Returns
TypeDescription
bool constexpr

static Instance()

Return the singleton instance for this application.

Returns
TypeDescription
LogSink &

static EnableStdClog(Severity)

This is also enabled if the "GOOGLE_CLOUD_CPP_ENABLE_CLOG" environment variable is set.

Parameter
NameDescription
min_severitySeverity
Returns
TypeDescription
void

static DisableStdClog()

Disablestd::clog onLogSink::Instance().

Note that this will remove the default logging backend.

Returns
TypeDescription
void

Type Aliases

BackendId

Alias Of:long

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-17 UTC.