Google Cloud C++ Client
0.4.0
C++ Client Library for Google Cloud Platform
|
Google Cloud Platform C++ Libraries logging framework. More...
#include "google/cloud/version.h"
#include <atomic>
#include <chrono>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <mutex>
#include <sstream>
Go to the source code of this file.
Classes | |
struct | google::cloud::v0::LogRecord |
Represents a single log message. More... | |
class | google::cloud::v0::LogBackend |
A sink to receive log records. More... | |
class | google::cloud::v0::LogSink |
struct | google::cloud::v0::NullStream |
Implements operator<< for all types, without any effect. More... | |
class | google::cloud::v0::Logger< compile_time_enabled > |
Define the class to capture a log message. More... | |
class | google::cloud::v0::Logger< false > |
Define the logger for a disabled log level. More... | |
Namespaces | |
google::cloud | |
Contains all the Google Cloud C++ Library APIs. | |
google::cloud::v0 | |
The Google Cloud C++ Library inlined, versioned namespace. | |
Macros | |
#define | GOOGLE_CLOUD_CPP_PP_CONCAT(a, b) a##b |
Concatenate two pre-processor tokens. More... | |
#define | GOOGLE_CLOUD_CPP_LOGGER_IDENTIFIER GOOGLE_CLOUD_CPP_PP_CONCAT(google_cloud_cpp_log_, __LINE__) |
Create a unique, or most likely unique identifier. More... | |
#define | GOOGLE_CLOUD_CPP_LOG_I(level, sink) |
The main entry point for the Google Cloud Platform C++ Library loggers. More... | |
#define | GCP_LOG(level) GOOGLE_CLOUD_CPP_LOG_I(GCP_LS_##level, ::google::cloud::LogSink::Instance()) |
Log a message with the Google Cloud Platform C++ Libraries logging framework. More... | |
#define | GOOGLE_CLOUD_CPP_LOGGING_MIN_SEVERITY_ENABLED GCP_LS_DEBUG |
Enumerations | |
enum | google::cloud::v0::Severity : int { google::cloud::v0::Severity::GCP_LS_TRACE, google::cloud::v0::Severity::GCP_LS_DEBUG, google::cloud::v0::Severity::GCP_LS_INFO, google::cloud::v0::Severity::GCP_LS_NOTICE, google::cloud::v0::Severity::GCP_LS_WARNING, google::cloud::v0::Severity::GCP_LS_ERROR, google::cloud::v0::Severity::GCP_LS_CRITICAL, google::cloud::v0::Severity::GCP_LS_ALERT, google::cloud::v0::Severity::GCP_LS_FATAL, google::cloud::v0::Severity::GCP_LS_HIGHEST = int(GCP_LS_FATAL), google::cloud::v0::Severity::GCP_LS_LOWEST = int(GCP_LS_TRACE), google::cloud::v0::Severity::GCP_LS_LOWEST_ENABLED = int(GOOGLE_CLOUD_CPP_LOGGING_MIN_SEVERITY_ENABLED) } |
Define the severity levels for Google Cloud Platform C++ Libraries logging. More... | |
Functions | |
std::ostream & | google::cloud::v0::operator<< (std::ostream &os, Severity x) |
Streaming operator, writes a human readable representation. More... | |
std::ostream & | google::cloud::v0::operator<< (std::ostream &os, LogRecord const &rhs) |
Default formatting of a LogRecord. More... | |
Google Cloud Platform C++ Libraries logging framework.
Some of the libraries need to log information to simplify troubleshooting. The functions and macros used for logging are defined in this file. In general, we abide by the following principles:
#ifdef
/#endif
directives around them.GCP_LOG()
macro to log from a Google Cloud Platform C++ library:std::clog
the application can call:Note that while std::clog
is buffered, the framework will flush any log message at severity WARNING
or higher.
Definition in file log.h.
#define GCP_LOG | ( | level | ) | GOOGLE_CLOUD_CPP_LOG_I(GCP_LS_##level, ::google::cloud::LogSink::Instance()) |
#define GOOGLE_CLOUD_CPP_LOG_I | ( | level, | |
sink | |||
) |
The main entry point for the Google Cloud Platform C++ Library loggers.
Typically this used only in tests, applications should use GCP_LOG(). This macro introduces a new scope (via the for-loop) with a single new identifier: GOOGLE_CLOUD_CPP_LOG_RECORD_IDENTIFIER We use a for-loop (as opposed to an if-statement, or a do-while), because then we can say:
and the variables are scoped correctly. The for-loop also affords us an opportunity to check that the log level is enabled before entering the body of the loop, and if disabled we can minimize the cost of the log. For example, disabled logs do not create an iostream at all.
Finally, the type of the GOOGLE_CLOUD_CPP_LOG_RECORD_IDENTIFIER changes if the log level is disabled at compile-time. For compile-time disabled log levels the compiler should be able to determine that the loop will not execute at all, and completely eliminate the code (we verified this using godbolt.org with modern GCC and Clang versions).
Note the use of fully-qualified class names, including the initial ::
, this is to prevent problems if anybody uses this macro in a context where Logger
is defined by the enclosing namespaces.
#define GOOGLE_CLOUD_CPP_LOGGER_IDENTIFIER GOOGLE_CLOUD_CPP_PP_CONCAT(google_cloud_cpp_log_, __LINE__) |
Create a unique, or most likely unique identifier.
In GCP_LOG() we need an identifier for the logger, we can easily create a C++ scope to make it work with any name, say "foo". However the user may have a variable called "foo" that they want to use in the scope (for example, to log the value of "foo". We try to make it unlikely that there will be collision by using an identifier that has a long prefix and depends on the line number.
#define GOOGLE_CLOUD_CPP_LOGGING_MIN_SEVERITY_ENABLED GCP_LS_DEBUG |