mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 20:14:23 +08:00
Use absl::NoDestructor for global log sinks.
PiperOrigin-RevId: 583235586 Change-Id: Ia472b8d6530fd829fed1c07558e152975d9b24ac
This commit is contained in:
committed by
Copybara-Service
parent
524ebb7ea9
commit
8197f8f1cd
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user