#include "absl/log/internal/log_sink_set.h"
#ifndef ABSL_HAVE_THREAD_LOCAL
#include <pthread.h>
#endif
#ifdef __ANDROID__
#include <android/log.h>
#endif
#ifdef _WIN32
#include <windows.h>
#endif
#include <algorithm>
#include <vector>
#include "absl/base/attributes.h"
#include "absl/base/call_once.h"
#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"
#include "absl/log/internal/config.h"
#include "absl/log/internal/globals.h"
#include "absl/log/log_entry.h"
#include "absl/log/log_sink.h"
#include "absl/strings/string_view.h"
#include "absl/synchronization/mutex.h"
#include "absl/types/span.h"
namespace absl {
ABSL_NAMESPACE_BEGIN
namespace log_internal {
namespace {
bool& ThreadIsLoggingStatus() { … }
class StderrLogSink final : public LogSink { … };
#if defined(__ANDROID__)
class AndroidLogSink final : public LogSink {
public:
~AndroidLogSink() override = default;
void Send(const absl::LogEntry& entry) override {
const int level = AndroidLogLevel(entry);
const char* const tag = GetAndroidNativeTag();
__android_log_write(level, tag,
entry.text_message_with_prefix_and_newline_c_str());
if (entry.log_severity() == absl::LogSeverity::kFatal)
__android_log_write(ANDROID_LOG_FATAL, tag, "terminating.\n");
}
private:
static int AndroidLogLevel(const absl::LogEntry& entry) {
switch (entry.log_severity()) {
case absl::LogSeverity::kFatal:
return ANDROID_LOG_FATAL;
case absl::LogSeverity::kError:
return ANDROID_LOG_ERROR;
case absl::LogSeverity::kWarning:
return ANDROID_LOG_WARN;
default:
if (entry.verbosity() >= 2) return ANDROID_LOG_VERBOSE;
if (entry.verbosity() == 1) return ANDROID_LOG_DEBUG;
return ANDROID_LOG_INFO;
}
}
};
#endif
#if defined(_WIN32)
class WindowsDebuggerLogSink final : public LogSink {
public:
~WindowsDebuggerLogSink() override = default;
void Send(const absl::LogEntry& entry) override {
if (entry.log_severity() < absl::StderrThreshold() &&
absl::log_internal::IsInitialized()) {
return;
}
::OutputDebugStringA(entry.text_message_with_prefix_and_newline_c_str());
}
};
#endif
class GlobalLogSinkSet final { … };
GlobalLogSinkSet& GlobalSinks() { … }
}
bool ThreadIsLoggingToLogSink() { … }
void LogToSinks(const absl::LogEntry& entry,
absl::Span<absl::LogSink*> extra_sinks, bool extra_sinks_only) { … }
void AddLogSink(absl::LogSink* sink) { … }
void RemoveLogSink(absl::LogSink* sink) { … }
void FlushLogSinks() { … }
}
ABSL_NAMESPACE_END
}