Google Cloud C++ Client 2.10.1
C++ Client Library for Google Cloud Platform
|
A sink to receive log records. More...
#include <google/cloud/log.h>
Public Types | |
using | BackendId = long |
Public Member Functions | |
LogSink () | |
bool | empty () const |
Return true if this object has no backends. More... | |
bool | is_enabled (Severity severity) const |
Return true if severity is enabled. More... | |
void | set_minimum_severity (Severity minimum) |
Severity | minimum_severity () const |
BackendId | AddBackend (std::shared_ptr< LogBackend > backend) |
void | RemoveBackend (BackendId id) |
void | ClearBackends () |
std::size_t | BackendCount () const |
void | Log (LogRecord log_record) |
void | Flush () |
Flush all the current backends. More... | |
Static Public Member Functions | |
static bool constexpr | CompileTimeEnabled (Severity level) |
Return true if the severity is enabled at compile time. More... | |
static LogSink & | Instance () |
Return the singleton instance for this application. More... | |
static void | EnableStdClog (Severity min_severity=Severity::GCP_LS_LOWEST_ENABLED) |
Enable std::clog on LogSink::Instance() . More... | |
static void | DisableStdClog () |
Disable std::clog on LogSink::Instance() . More... | |
A sink to receive log records.
using google::cloud::LogSink::BackendId = long |
google::cloud::LogSink::LogSink | ( | ) |
BackendId google::cloud::LogSink::AddBackend | ( | std::shared_ptr< LogBackend > | backend | ) |
std::size_t google::cloud::LogSink::BackendCount | ( | ) | const |
void google::cloud::LogSink::ClearBackends | ( | ) |
|
inlinestaticconstexpr |
Return true if the severity is enabled at compile time.
|
inlinestatic |
Disable std::clog
on LogSink::Instance()
.
Note that this will remove the default logging backend.
|
inline |
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.
|
inlinestatic |
Enable std::clog
on LogSink::Instance()
.
This is also enabled if the "GOOGLE_CLOUD_CPP_ENABLE_CLOG" environment variable is set.
void google::cloud::LogSink::Flush | ( | ) |
Flush all the current backends.
|
static |
Return the singleton instance for this application.
|
inline |
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.
void google::cloud::LogSink::Log | ( | LogRecord | log_record | ) |
|
inline |
void google::cloud::LogSink::RemoveBackend | ( | BackendId | id | ) |
|
inline |