summaryrefslogtreecommitdiff
path: root/absl/log/globals.cc
diff options
context:
space:
mode:
Diffstat (limited to 'absl/log/globals.cc')
-rw-r--r--absl/log/globals.cc40
1 files changed, 35 insertions, 5 deletions
diff --git a/absl/log/globals.cc b/absl/log/globals.cc
index 6dfe81f0..cc85438f 100644
--- a/absl/log/globals.cc
+++ b/absl/log/globals.cc
@@ -14,14 +14,17 @@
#include "absl/log/globals.h"
-#include <stddef.h>
-#include <stdint.h>
-
#include <atomic>
+#include <cstddef>
+#include <cstdint>
+#include <cstdlib>
+#include <cstring>
+#include <string>
#include "absl/base/attributes.h"
#include "absl/base/config.h"
#include "absl/base/internal/atomic_hook.h"
+#include "absl/base/internal/raw_logging.h"
#include "absl/base/log_severity.h"
#include "absl/hash/hash.h"
#include "absl/strings/string_view.h"
@@ -43,6 +46,9 @@ ABSL_CONST_INIT std::atomic<int> stderrthreshold{
ABSL_CONST_INIT std::atomic<size_t> log_backtrace_at_hash{0};
ABSL_CONST_INIT std::atomic<bool> prepend_log_prefix{true};
+constexpr char kDefaultAndroidTag[] = "native";
+ABSL_CONST_INIT std::atomic<const char*> android_log_tag{kDefaultAndroidTag};
+
ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES
absl::base_internal::AtomicHook<log_internal::LoggingGlobalsListener>
logging_globals_listener;
@@ -121,9 +127,29 @@ ScopedStderrThreshold::~ScopedStderrThreshold() {
namespace log_internal {
+const char* GetAndroidNativeTag() {
+ return android_log_tag.load(std::memory_order_acquire);
+}
+
+} // namespace log_internal
+
+void SetAndroidNativeTag(const char* tag) {
+ ABSL_CONST_INIT static std::atomic<const std::string*> user_log_tag(nullptr);
+ ABSL_INTERNAL_CHECK(tag, "tag must be non-null.");
+
+ const std::string* tag_str = new std::string(tag);
+ ABSL_INTERNAL_CHECK(
+ android_log_tag.exchange(tag_str->c_str(), std::memory_order_acq_rel) ==
+ kDefaultAndroidTag,
+ "SetAndroidNativeTag() must only be called once per process!");
+ user_log_tag.store(tag_str, std::memory_order_relaxed);
+}
+
+namespace log_internal {
+
bool ShouldLogBacktraceAt(absl::string_view file, int line) {
const size_t flag_hash =
- log_backtrace_at_hash.load(std::memory_order_acquire);
+ log_backtrace_at_hash.load(std::memory_order_relaxed);
return flag_hash != 0 && flag_hash == HashSiteForLogBacktraceAt(file, line);
}
@@ -132,7 +158,11 @@ bool ShouldLogBacktraceAt(absl::string_view file, int line) {
void SetLogBacktraceLocation(absl::string_view file, int line) {
log_backtrace_at_hash.store(HashSiteForLogBacktraceAt(file, line),
- std::memory_order_release);
+ std::memory_order_relaxed);
+}
+
+void ClearLogBacktraceLocation() {
+ log_backtrace_at_hash.store(0, std::memory_order_relaxed);
}
bool ShouldPrependLogPrefix() {