15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_LOG_H_ 16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_LOG_H_ 79 #include "google/cloud/version.h" 93 #define GOOGLE_CLOUD_CPP_PP_CONCAT(a, b) a##b 104 #define GOOGLE_CLOUD_CPP_LOGGER_IDENTIFIER 135 #define GOOGLE_CLOUD_CPP_LOG_I(level, sink) 137 ::google::cloud::LogSink::CompileTimeEnabled( 138 ::google::cloud::Severity::level)>( 139 ::google::cloud::Severity::level, __func__, __FILE__, __LINE__, 154 #define GCP_LOG(level) 157 #ifndef GOOGLE_CLOUD_CPP_LOGGING_MIN_SEVERITY_ENABLED 158 #define GOOGLE_CLOUD_CPP_LOGGING_MIN_SEVERITY_ENABLED GCP_LS_DEBUG 202 std::ostream& operator<<(std::ostream& os,
Severity x);
217 std::ostream& operator<<(std::ostream& os,
LogRecord const& rhs);
263 bool empty()
const {
return empty_.load(std::memory_order_relaxed); }
282 auto minimum = minimum_severity_.load(std::memory_order_relaxed);
283 return static_cast<
int>(severity) >= minimum;
287 minimum_severity_.store(
static_cast<
int>(minimum));
290 return static_cast<
Severity>(minimum_severity_.load());
307 void EnableStdClogImpl();
308 void DisableStdClogImpl();
309 long AddBackendImpl(std::shared_ptr<
LogBackend> backend);
310 void RemoveBackendImpl(
long id);
312 std::atomic<
bool> empty_;
313 std::atomic<
int> minimum_severity_;
314 std::mutex
mutable mu_;
316 long clog_backend_id_;
317 std::map<
long, std::shared_ptr<
LogBackend>> backends_;
330 template <
typename T>
343 template <
bool compile_time_enabled>
348 : severity_(severity),
359 if (!stream_ || !enabled_) {
368 record
.timestamp = std::chrono::system_clock::now();
370 sink
.Log(std::move(record)
);
376 stream_.reset(
new std::ostringstream);
384 char const* function_;
385 char const* filename_;
387 std::unique_ptr<std::ostringstream> stream_;
396 Logger<
false>() =
default;
404 constexpr bool enabled()
const {
return false; }
void set_minimum_severity(Severity minimum)
Use this level for debug messages that should not be present in production.
A sink to receive log records.
#define GOOGLE_CLOUD_CPP_NS
Implements operator<< for all types, without any effect.
virtual ~LogBackend()=default
Contains all the Google Cloud C++ Library APIs.
The system is about to crash or terminate.
long AddBackend(std::shared_ptr< LogBackend > backend)
void Log(LogRecord log_record)
constexpr bool enabled() const
Use this level for messages that indicate the code is entering and leaving functions.
The highest possible severity level.
#define GOOGLE_CLOUD_CPP_LOGGING_MIN_SEVERITY_ENABLED
The lowest possible severity level.
An error has been detected.
Informational messages, such as unusual, but expected conditions.
static constexpr bool CompileTimeEnabled(Severity level)
Return true if the severity is enabled at compile time.
#define GOOGLE_CLOUD_CPP_LOGGER_IDENTIFIER
Create a unique, or most likely unique identifier.
The system is in a critical state, such as running out of local resources.
static void EnableStdClog()
Enable std::clog on LogSink::Instance().
Informational messages, such as normal progress.
virtual void ProcessWithOwnership(LogRecord log_record)=0
void RemoveBackend(long id)
void LogTo(LogSink &sink)
Send the log record captured by this object to sink.
bool empty() const
Return true if this object has no backends.
Severity
Define the severity levels for Google Cloud Platform C++ Libraries logging.
The system is at risk of immediate failure.
std::ostream & Stream()
Return the iostream that captures the log message.
Represents a single log message.
std::chrono::system_clock::time_point timestamp
Logger(Severity severity, char const *function, char const *filename, int lineno, LogSink &sink)
static void DisableStdClog()
Disable std::clog on LogSink::Instance().
static LogSink & Instance()
Return the singleton instance for this application.
bool is_enabled(Severity severity) const
Return true if severity is enabled.
#define GOOGLE_CLOUD_CPP_LOG_I(level, sink)
The main entry point for the Google Cloud Platform C++ Library loggers.
std::size_t BackendCount() const
The lowest level that is enabled at compile-time.
#define GOOGLE_CLOUD_CPP_PP_CONCAT(a, b)
Concatenate two pre-processor tokens.
Define the class to capture a log message.
An indication of problems, users may need to take action.
Severity minimum_severity() const
virtual void Process(LogRecord const &log_record)=0