Google Cloud C++ Client
2.7.0
C++ Client Library for Google Cloud Platform
|
Google Cloud Platform C++ Libraries logging framework. More...
#include "google/cloud/version.h"
#include "absl/memory/memory.h"
#include <atomic>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <mutex>
#include <sstream>
#include <string>
#include <thread>
Go to the source code of this file.
Classes | |
struct | google::cloud::LogRecord |
Represents a single log message. More... | |
class | google::cloud::LogBackend |
The logging backend interface. More... | |
class | google::cloud::LogSink |
A sink to receive log records. More... | |
struct | google::cloud::NullStream |
Implements operator<< for all types, without any effect. More... | |
class | google::cloud::Logger< CompileTimeEnabled > |
Define the class to capture a log message. More... | |
class | google::cloud::Logger< false > |
Define the logger for a disabled log level. More... | |
Namespaces | |
google::cloud | |
Contains all the Google Cloud C++ Library APIs. | |
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 class | google::cloud::Severity : int { google::cloud::GCP_LS_TRACE , google::cloud::GCP_LS_DEBUG , google::cloud::GCP_LS_INFO , google::cloud::GCP_LS_NOTICE , google::cloud::GCP_LS_WARNING , google::cloud::GCP_LS_ERROR , google::cloud::GCP_LS_CRITICAL , google::cloud::GCP_LS_ALERT , google::cloud::GCP_LS_FATAL , google::cloud::GCP_LS_HIGHEST = GCP_LS_FATAL , google::cloud::GCP_LS_LOWEST = GCP_LS_TRACE , google::cloud::GCP_LS_LOWEST_ENABLED = GOOGLE_CLOUD_CPP_LOGGING_MIN_SEVERITY_ENABLED } |
Define the severity levels for Google Cloud Platform C++ Libraries logging. More... | |
Functions | |
std::ostream & | google::cloud::operator<< (std::ostream &os, Severity x) |
Streaming operator, writes a human readable representation. More... | |
std::ostream & | google::cloud::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:
std::clog
immediately before a GCP_LOG(FATAL) terminates the process.#ifdef
/#endif
directives around them.GCP_LOG()
macro to log from a Google Cloud Platform C++ library:std::clog
the application can call:Alternatively, the application can enable logging to std::clog
without any code changes or recompiling by setting the "GOOGLE_CLOUD_CPP_ENABLE_CLOG" environment variable before the program starts. The existence of this variable is all that matters; the value is ignored.
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 |