diff --git a/absl/log/CMakeLists.txt b/absl/log/CMakeLists.txt index 1ca35a16649..aa0088653d5 100644 --- a/absl/log/CMakeLists.txt +++ b/absl/log/CMakeLists.txt @@ -238,6 +238,7 @@ absl_cc_library( absl::log_entry absl::log_severity absl::log_sink + absl::no_destructor absl::raw_logging_internal absl::synchronization absl::span diff --git a/absl/log/internal/BUILD.bazel b/absl/log/internal/BUILD.bazel index c656404f88a..2030a3d7ec3 100644 --- a/absl/log/internal/BUILD.bazel +++ b/absl/log/internal/BUILD.bazel @@ -220,6 +220,7 @@ cc_library( "//absl/base:config", "//absl/base:core_headers", "//absl/base:log_severity", + "//absl/base:no_destructor", "//absl/base:raw_logging_internal", "//absl/cleanup", "//absl/log:globals", diff --git a/absl/log/internal/log_sink_set.cc b/absl/log/internal/log_sink_set.cc index b7cbe36455b..3d5c69952c2 100644 --- a/absl/log/internal/log_sink_set.cc +++ b/absl/log/internal/log_sink_set.cc @@ -35,6 +35,7 @@ #include "absl/base/config.h" #include "absl/base/internal/raw_logging.h" #include "absl/base/log_severity.h" +#include "absl/base/no_destructor.h" #include "absl/base/thread_annotations.h" #include "absl/cleanup/cleanup.h" #include "absl/log/globals.h" @@ -168,17 +169,16 @@ class GlobalLogSinkSet final { #if defined(__myriad2__) || defined(__Fuchsia__) // myriad2 and Fuchsia do not log to stderr by default. #else - static StderrLogSink* stderr_log_sink = new StderrLogSink; - AddLogSink(stderr_log_sink); + static absl::NoDestructor stderr_log_sink; + AddLogSink(stderr_log_sink.get()); #endif #ifdef __ANDROID__ - static AndroidLogSink* android_log_sink = new AndroidLogSink; - AddLogSink(android_log_sink); + static absl::NoDestructor android_log_sink; + AddLogSink(android_log_sink.get()); #endif #if defined(_WIN32) - static WindowsDebuggerLogSink* debugger_log_sink = - new WindowsDebuggerLogSink; - AddLogSink(debugger_log_sink); + static absl::NoDestructor debugger_log_sink; + AddLogSink(debugger_log_sink.get()); #endif // !defined(_WIN32) } @@ -268,7 +268,7 @@ class GlobalLogSinkSet final { // Returns reference to the global LogSinks set. GlobalLogSinkSet& GlobalSinks() { - static GlobalLogSinkSet* global_sinks = new GlobalLogSinkSet; + static absl::NoDestructor global_sinks; return *global_sinks; }