xref: /aosp_15_r20/external/libchrome/libchrome_tools/patch/logging.patch (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Workerdiff --git a/base/logging.cc b/base/logging.cc
2*635a8641SAndroid Build Coastguard Workerindex 8eabda0..112afb8 100644
3*635a8641SAndroid Build Coastguard Worker--- a/base/logging.cc
4*635a8641SAndroid Build Coastguard Worker+++ b/base/logging.cc
5*635a8641SAndroid Build Coastguard Worker@@ -58,7 +58,7 @@ typedef HANDLE MutexHandle;
6*635a8641SAndroid Build Coastguard Worker #include <zircon/syscalls.h>
7*635a8641SAndroid Build Coastguard Worker #endif
8*635a8641SAndroid Build Coastguard Worker
9*635a8641SAndroid Build Coastguard Worker-#if defined(OS_ANDROID)
10*635a8641SAndroid Build Coastguard Worker+#if defined(OS_ANDROID) || defined(__ANDROID__)
11*635a8641SAndroid Build Coastguard Worker #include <android/log.h>
12*635a8641SAndroid Build Coastguard Worker #endif
13*635a8641SAndroid Build Coastguard Worker
14*635a8641SAndroid Build Coastguard Worker@@ -407,21 +407,23 @@ bool BaseInitLoggingImpl(const LoggingSettings& settings) {
15*635a8641SAndroid Build Coastguard Worker   // Can log only to the system debug log.
16*635a8641SAndroid Build Coastguard Worker   CHECK_EQ(settings.logging_dest & ~LOG_TO_SYSTEM_DEBUG_LOG, 0);
17*635a8641SAndroid Build Coastguard Worker #endif
18*635a8641SAndroid Build Coastguard Worker-  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
19*635a8641SAndroid Build Coastguard Worker-  // Don't bother initializing |g_vlog_info| unless we use one of the
20*635a8641SAndroid Build Coastguard Worker-  // vlog switches.
21*635a8641SAndroid Build Coastguard Worker-  if (command_line->HasSwitch(switches::kV) ||
22*635a8641SAndroid Build Coastguard Worker-      command_line->HasSwitch(switches::kVModule)) {
23*635a8641SAndroid Build Coastguard Worker-    // NOTE: If |g_vlog_info| has already been initialized, it might be in use
24*635a8641SAndroid Build Coastguard Worker-    // by another thread. Don't delete the old VLogInfo, just create a second
25*635a8641SAndroid Build Coastguard Worker-    // one. We keep track of both to avoid memory leak warnings.
26*635a8641SAndroid Build Coastguard Worker-    CHECK(!g_vlog_info_prev);
27*635a8641SAndroid Build Coastguard Worker-    g_vlog_info_prev = g_vlog_info;
28*635a8641SAndroid Build Coastguard Worker-
29*635a8641SAndroid Build Coastguard Worker-    g_vlog_info =
30*635a8641SAndroid Build Coastguard Worker-        new VlogInfo(command_line->GetSwitchValueASCII(switches::kV),
31*635a8641SAndroid Build Coastguard Worker-                     command_line->GetSwitchValueASCII(switches::kVModule),
32*635a8641SAndroid Build Coastguard Worker-                     &g_min_log_level);
33*635a8641SAndroid Build Coastguard Worker+  if (base::CommandLine::InitializedForCurrentProcess()) {
34*635a8641SAndroid Build Coastguard Worker+    base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
35*635a8641SAndroid Build Coastguard Worker+    // Don't bother initializing |g_vlog_info| unless we use one of the
36*635a8641SAndroid Build Coastguard Worker+    // vlog switches.
37*635a8641SAndroid Build Coastguard Worker+    if (command_line->HasSwitch(switches::kV) ||
38*635a8641SAndroid Build Coastguard Worker+        command_line->HasSwitch(switches::kVModule)) {
39*635a8641SAndroid Build Coastguard Worker+      // NOTE: If |g_vlog_info| has already been initialized, it might be in use
40*635a8641SAndroid Build Coastguard Worker+      // by another thread. Don't delete the old VLogInfo, just create a second
41*635a8641SAndroid Build Coastguard Worker+      // one. We keep track of both to avoid memory leak warnings.
42*635a8641SAndroid Build Coastguard Worker+      CHECK(!g_vlog_info_prev);
43*635a8641SAndroid Build Coastguard Worker+      g_vlog_info_prev = g_vlog_info;
44*635a8641SAndroid Build Coastguard Worker+
45*635a8641SAndroid Build Coastguard Worker+      g_vlog_info =
46*635a8641SAndroid Build Coastguard Worker+          new VlogInfo(command_line->GetSwitchValueASCII(switches::kV),
47*635a8641SAndroid Build Coastguard Worker+                       command_line->GetSwitchValueASCII(switches::kVModule),
48*635a8641SAndroid Build Coastguard Worker+                       &g_min_log_level);
49*635a8641SAndroid Build Coastguard Worker+    }
50*635a8641SAndroid Build Coastguard Worker   }
51*635a8641SAndroid Build Coastguard Worker
52*635a8641SAndroid Build Coastguard Worker   g_logging_destination = settings.logging_dest;
53*635a8641SAndroid Build Coastguard Worker@@ -755,7 +757,7 @@ LogMessage::~LogMessage() {
54*635a8641SAndroid Build Coastguard Worker                        str_newline.c_str());
55*635a8641SAndroid Build Coastguard Worker #endif  // defined(USE_ASL)
56*635a8641SAndroid Build Coastguard Worker     }
57*635a8641SAndroid Build Coastguard Worker-#elif defined(OS_ANDROID)
58*635a8641SAndroid Build Coastguard Worker+#elif defined(OS_ANDROID) || defined(__ANDROID__)
59*635a8641SAndroid Build Coastguard Worker     android_LogPriority priority =
60*635a8641SAndroid Build Coastguard Worker         (severity_ < 0) ? ANDROID_LOG_VERBOSE : ANDROID_LOG_UNKNOWN;
61*635a8641SAndroid Build Coastguard Worker     switch (severity_) {
62*635a8641SAndroid Build Coastguard Worker@@ -772,7 +774,16 @@ LogMessage::~LogMessage() {
63*635a8641SAndroid Build Coastguard Worker         priority = ANDROID_LOG_FATAL;
64*635a8641SAndroid Build Coastguard Worker         break;
65*635a8641SAndroid Build Coastguard Worker     }
66*635a8641SAndroid Build Coastguard Worker+#if defined(OS_ANDROID)
67*635a8641SAndroid Build Coastguard Worker     __android_log_write(priority, "chromium", str_newline.c_str());
68*635a8641SAndroid Build Coastguard Worker+#else
69*635a8641SAndroid Build Coastguard Worker+    __android_log_write(
70*635a8641SAndroid Build Coastguard Worker+        priority,
71*635a8641SAndroid Build Coastguard Worker+        base::CommandLine::InitializedForCurrentProcess() ?
72*635a8641SAndroid Build Coastguard Worker+            base::CommandLine::ForCurrentProcess()->
73*635a8641SAndroid Build Coastguard Worker+                GetProgram().BaseName().value().c_str() : nullptr,
74*635a8641SAndroid Build Coastguard Worker+        str_newline.c_str());
75*635a8641SAndroid Build Coastguard Worker+#endif  // defined(OS_ANDROID)
76*635a8641SAndroid Build Coastguard Worker #endif
77*635a8641SAndroid Build Coastguard Worker     ignore_result(fwrite(str_newline.data(), str_newline.size(), 1, stderr));
78*635a8641SAndroid Build Coastguard Worker     fflush(stderr);
79