15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_LOG_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_LOG_H
87 #include "google/cloud/version.h"
88 #include "absl/memory/memory.h"
105 #define GOOGLE_CLOUD_CPP_PP_CONCAT(a, b) a##b
116 #define GOOGLE_CLOUD_CPP_LOGGER_IDENTIFIER
147 #define GOOGLE_CLOUD_CPP_LOG_I(level, sink)
148 for (::google::cloud::Logger<::google::cloud::LogSink::CompileTimeEnabled(
149 ::google::cloud::Severity::level)>
151 ::google::cloud::Severity::level, __func__, __FILE__, __LINE__,
166 #define GCP_LOG(level)
169 #ifndef GOOGLE_CLOUD_CPP_LOGGING_MIN_SEVERITY_ENABLED
170 #define GOOGLE_CLOUD_CPP_LOGGING_MIN_SEVERITY_ENABLED GCP_LS_DEBUG
215 std::ostream& operator<<(std::ostream& os,
Severity x);
231 std::ostream& operator<<(std::ostream& os,
LogRecord const& rhs);
278 bool empty()
const {
return empty_.load(std::memory_order_relaxed); }
297 auto minimum = minimum_severity_.load(std::memory_order_relaxed);
298 return static_cast<
int>(severity) >= minimum;
302 minimum_severity_.store(
static_cast<
int>(minimum));
305 return static_cast<
Severity>(minimum_severity_.load());
313 using BackendId =
long;
344 void EnableStdClogImpl(
Severity min_severity);
345 void DisableStdClogImpl();
346 void SetDefaultBackend(std::shared_ptr<
LogBackend> backend);
347 BackendId AddBackendImpl(std::shared_ptr<
LogBackend> backend);
348 void RemoveBackendImpl(BackendId id);
350 std::map<BackendId, std::shared_ptr<
LogBackend>> CopyBackends();
352 std::atomic<
bool> empty_;
353 std::atomic<
int> minimum_severity_;
354 std::mutex
mutable mu_;
355 BackendId next_id_ = 0;
356 BackendId default_backend_id_ = 0;
357 std::map<BackendId, std::shared_ptr<
LogBackend>> backends_;
370 template <
typename T>
383 template <
bool CompileTimeEnabled>
402 if (!stream_ || !enabled_) {
411 record
.thread_id = std::this_thread::get_id();
412 record
.timestamp = std::chrono::system_clock::now();
414 sink
.Log(std::move(record)
);
419 if (!stream_) stream_ = absl::make_unique<std::ostringstream>();
426 char const* function_;
427 char const* filename_;
429 std::unique_ptr<std::ostringstream> stream_;
439 : severity_(severity) {}
461 std::shared_ptr<
LogBackend> DefaultLogBackend();