summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2023-11-16 19:13:40 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2023-11-16 19:14:45 -0800
commit8197f8f1cd8223e85cb8a7fe7a2530385bb9be7d (patch)
treeeb89e7beecfdc2af1ffa1544f97b446cd673f079
parent524ebb7ea91d2955dc4c68c7e6fd2bed620621b5 (diff)
Use absl::NoDestructor for global log sinks.
PiperOrigin-RevId: 583235586 Change-Id: Ia472b8d6530fd829fed1c07558e152975d9b24ac
-rw-r--r--absl/log/CMakeLists.txt1
-rw-r--r--absl/log/internal/BUILD.bazel1
-rw-r--r--absl/log/internal/log_sink_set.cc16
3 files changed, 10 insertions, 8 deletions
diff --git a/absl/log/CMakeLists.txt b/absl/log/CMakeLists.txt
index 1ca35a16..aa008865 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 c656404f..2030a3d7 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 b7cbe364..3d5c6995 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<StderrLogSink> 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<AndroidLogSink> 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<WindowsDebuggerLogSink> 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<GlobalLogSinkSet> global_sinks;
return *global_sinks;
}