Google Cloud C++ Client  0.4.0
C++ Client Library for Google Cloud Platform
Public Member Functions | Static Public Member Functions | List of all members
google::cloud::v0::LogSink Class Reference

#include <google/cloud/log.h>

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
 
long AddBackend (std::shared_ptr< LogBackend > backend)
 
void RemoveBackend (long id)
 
void ClearBackends ()
 
std::size_t BackendCount () const
 
void Log (LogRecord log_record)
 

Static Public Member Functions

static constexpr bool CompileTimeEnabled (Severity level)
 Return true if the severity is enabled at compile time. More...
 
static LogSinkInstance ()
 Return the singleton instance for this application. More...
 
static void EnableStdClog ()
 Enable std::clog on LogSink::Instance(). More...
 
static void DisableStdClog ()
 Disable std::clog on LogSink::Instance(). More...
 

Detailed Description

Definition at line 233 of file log.h.

Constructor & Destructor Documentation

◆ LogSink()

google::cloud::v0::LogSink::LogSink ( )

Definition at line 41 of file log.cc.

Member Function Documentation

◆ AddBackend()

long google::cloud::v0::LogSink::AddBackend ( std::shared_ptr< LogBackend backend)

Definition at line 52 of file log.cc.

◆ BackendCount()

std::size_t google::cloud::v0::LogSink::BackendCount ( ) const

Definition at line 69 of file log.cc.

◆ ClearBackends()

void google::cloud::v0::LogSink::ClearBackends ( )

Definition at line 62 of file log.cc.

◆ CompileTimeEnabled()

static constexpr bool google::cloud::v0::LogSink::CompileTimeEnabled ( Severity  level)
inlinestatic

Return true if the severity is enabled at compile time.

Definition at line 238 of file log.h.

◆ DisableStdClog()

static void google::cloud::v0::LogSink::DisableStdClog ( )
inlinestatic

Disable std::clog on LogSink::Instance().

Definition at line 304 of file log.h.

◆ empty()

bool google::cloud::v0::LogSink::empty ( ) const
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.

Definition at line 263 of file log.h.

◆ EnableStdClog()

static void google::cloud::v0::LogSink::EnableStdClog ( )
inlinestatic

Enable std::clog on LogSink::Instance().

Definition at line 301 of file log.h.

◆ Instance()

LogSink & google::cloud::v0::LogSink::Instance ( )
static

Return the singleton instance for this application.

Definition at line 47 of file log.cc.

◆ is_enabled()

bool google::cloud::v0::LogSink::is_enabled ( Severity  severity) const
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.

Definition at line 281 of file log.h.

◆ Log()

void google::cloud::v0::LogSink::Log ( LogRecord  log_record)

Definition at line 74 of file log.cc.

◆ minimum_severity()

Severity google::cloud::v0::LogSink::minimum_severity ( ) const
inline

Definition at line 289 of file log.h.

◆ RemoveBackend()

void google::cloud::v0::LogSink::RemoveBackend ( long  id)

Definition at line 57 of file log.cc.

◆ set_minimum_severity()

void google::cloud::v0::LogSink::set_minimum_severity ( Severity  minimum)
inline

Definition at line 286 of file log.h.