15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_LOG_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_LOG_H
87 #include "google/cloud/version.h"
104 #define GOOGLE_CLOUD_CPP_PP_CONCAT(a, b) a##b
115 #define GOOGLE_CLOUD_CPP_LOGGER_IDENTIFIER
146 #define GOOGLE_CLOUD_CPP_LOG_I(level, sink)
147 for (::google::cloud::Logger<::google::cloud::LogSink::CompileTimeEnabled(
148 ::google::cloud::Severity::level)>
150 ::google::cloud::Severity::level, __func__, __FILE__, __LINE__,
165 #define GCP_LOG(level)
168 #ifndef GOOGLE_CLOUD_CPP_LOGGING_MIN_SEVERITY_ENABLED
169 #define GOOGLE_CLOUD_CPP_LOGGING_MIN_SEVERITY_ENABLED GCP_LS_DEBUG
214 std::ostream& operator<<(std::ostream& os,
Severity x);
230 std::ostream& operator<<(std::ostream& os,
LogRecord const& rhs);
277 bool empty()
const {
return empty_.load(std::memory_order_relaxed); }
296 auto minimum = minimum_severity_.load(std::memory_order_relaxed);
297 return static_cast<
int>(severity) >= minimum;
301 minimum_severity_.store(
static_cast<
int>(minimum));
304 return static_cast<
Severity>(minimum_severity_.load());
312 using BackendId =
long;
343 void EnableStdClogImpl(
Severity min_severity);
344 void DisableStdClogImpl();
345 void SetDefaultBackend(std::shared_ptr<
LogBackend> backend);
346 BackendId AddBackendImpl(std::shared_ptr<
LogBackend> backend);
347 void RemoveBackendImpl(BackendId id);
349 std::map<BackendId, std::shared_ptr<
LogBackend>> CopyBackends();
351 std::atomic<
bool> empty_;
352 std::atomic<
int> minimum_severity_;
353 std::mutex
mutable mu_;
354 BackendId next_id_ = 0;
355 BackendId default_backend_id_ = 0;
356 std::map<BackendId, std::shared_ptr<
LogBackend>> backends_;
369 template <
typename T>
382 template <
bool CompileTimeEnabled>
401 if (!stream_ || !enabled_) {
410 record
.thread_id = std::this_thread::get_id();
411 record
.timestamp = std::chrono::system_clock::now();
413 sink
.Log(std::move(record)
);
419 stream_.reset(
new std::ostringstream);
427 char const* function_;
428 char const* filename_;
430 std::unique_ptr<std::ostringstream> stream_;
440 : severity_(severity) {}
463 std::shared_ptr<
LogBackend> DefaultLogBackend();