blob: 7d36c187fe7e2cdbd0b7650d861933698417cee8 [file] [log] [blame]
[email protected]63e66802012-01-18 21:21:091// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitd7cae122008-07-26 21:49:384
[email protected]b16ef312008-08-19 18:36:235#include "base/logging.h"
[email protected]f6abeba2008-08-08 13:27:286
Hans Wennborg12aea3e2020-04-14 15:29:007// logging.h is a widely included header and its size has significant impact on
8// build time. Try not to raise this limit unless absolutely necessary. See
9// https://chromium.googlesource.com/chromium/src/+/HEAD/docs/wmax_tokens.md
10#ifndef NACL_TC_REV
Hans Wennborg944479f2020-06-25 21:39:2511#pragma clang max_tokens_here 350000
Hans Wennborg12aea3e2020-04-14 15:29:0012#endif // NACL_TC_REV
13
Hans Wennborg944479f2020-06-25 21:39:2514#ifdef BASE_CHECK_H_
15#error "logging.h should not include check.h"
16#endif
17
avi51ba3e692015-12-26 17:30:5018#include <limits.h>
avi9b6f42932015-12-26 22:15:1419#include <stdint.h>
20
David Bienvenub4b441e2020-09-23 05:49:5721#include <vector>
22
Chris Hamilton306740d2019-04-25 18:48:3623#include "base/pending_task.h"
Weze976b732018-10-20 03:37:3124#include "base/stl_util.h"
Jan Wilken Dörrie4a498d8c2021-01-20 10:19:3925#include "base/strings/string_piece.h"
Chris Hamilton306740d2019-04-25 18:48:3626#include "base/task/common/task_annotator.h"
Eric Secklerf6c544f2020-06-02 10:49:2127#include "base/trace_event/base_tracing.h"
avi9b6f42932015-12-26 22:15:1428#include "build/build_config.h"
avi51ba3e692015-12-26 17:30:5029
[email protected]b16ef312008-08-19 18:36:2330#if defined(OS_WIN)
[email protected]e36ddc82009-12-08 04:22:5031#include <io.h>
alex-accc1bde62017-04-19 08:33:5532#include <windows.h>
[email protected]f6abeba2008-08-08 13:27:2833typedef HANDLE FileHandle;
[email protected]e36ddc82009-12-08 04:22:5034// Windows warns on using write(). It prefers _write().
35#define write(fd, buf, count) _write(fd, buf, static_cast<unsigned int>(count))
36// Windows doesn't define STDERR_FILENO. Define it here.
37#define STDERR_FILENO 2
Eric Noyaufce100702017-10-16 09:46:3438
Avi Drissman5b286372020-07-28 21:59:3839#elif defined(OS_APPLE)
Eric Noyaufce100702017-10-16 09:46:3440// In MacOS 10.12 and iOS 10.0 and later ASL (Apple System Log) was deprecated
41// in favor of OS_LOG (Unified Logging).
42#include <AvailabilityMacros.h>
43#if defined(OS_IOS)
44#if !defined(__IPHONE_10_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0
45#define USE_ASL
46#endif
47#else // !defined(OS_IOS)
48#if !defined(MAC_OS_X_VERSION_10_12) || \
49 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
50#define USE_ASL
51#endif
52#endif // defined(OS_IOS)
53
54#if defined(USE_ASL)
mark4c7449c2015-11-10 19:53:4255#include <asl.h>
Eric Noyaufce100702017-10-16 09:46:3456#else
57#include <os/log.h>
58#endif
59
mark4c7449c2015-11-10 19:53:4260#include <CoreFoundation/CoreFoundation.h>
[email protected]f6abeba2008-08-08 13:27:2861#include <mach/mach.h>
62#include <mach/mach_time.h>
63#include <mach-o/dyld.h>
Eric Noyaufce100702017-10-16 09:46:3464
Fabrice de Gans-Riberi306871de2018-05-16 19:38:3965#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
[email protected]19ea84ca2010-11-12 08:37:0866#if defined(OS_NACL)
thestig75f87352014-12-03 21:42:2767#include <sys/time.h> // timespec doesn't seem to be in <time.h>
[email protected]19ea84ca2010-11-12 08:37:0868#endif
[email protected]052f1b52008-11-06 21:43:0769#include <time.h>
[email protected]614e9fa2008-08-11 22:52:5970#endif
71
Fabrice de Gans-Riberi306871de2018-05-16 19:38:3972#if defined(OS_FUCHSIA)
Sharon Yanga4b908de2019-05-07 22:19:0373#include <lib/syslog/global.h>
74#include <lib/syslog/logger.h>
Fabrice de Gans-Riberi306871de2018-05-16 19:38:3975#include <zircon/process.h>
76#include <zircon/syscalls.h>
77#endif
78
79#if defined(OS_ANDROID)
80#include <android/log.h>
81#endif
82
83#if defined(OS_POSIX) || defined(OS_FUCHSIA)
[email protected]d8617a62009-10-09 23:52:2084#include <errno.h>
mark4c7449c2015-11-10 19:53:4285#include <paths.h>
[email protected]f6abeba2008-08-08 13:27:2886#include <stdio.h>
[email protected]eb62f7262013-03-30 14:29:0087#include <stdlib.h>
[email protected]f6abeba2008-08-08 13:27:2888#include <string.h>
mark4c7449c2015-11-10 19:53:4289#include <sys/stat.h>
Chris Findeisen2a373a2d2019-08-15 19:44:3090#include "base/process/process_handle.h"
[email protected]f6abeba2008-08-08 13:27:2891#define MAX_PATH PATH_MAX
92typedef FILE* FileHandle;
[email protected]f6abeba2008-08-08 13:27:2893#endif
94
[email protected]1f88b5162011-04-01 00:02:2995#include <algorithm>
96#include <cstring>
initial.commitd7cae122008-07-26 21:49:3897#include <ctime>
98#include <iomanip>
[email protected]1f88b5162011-04-01 00:02:2999#include <ostream>
[email protected]c914d8a2014-04-23 01:11:01100#include <string>
alex-accc1bde62017-04-19 08:33:55101#include <utility>
[email protected]b16ef312008-08-19 18:36:23102
initial.commitd7cae122008-07-26 21:49:38103#include "base/base_switches.h"
alex-accc1bde62017-04-19 08:33:55104#include "base/callback.h"
initial.commitd7cae122008-07-26 21:49:38105#include "base/command_line.h"
Brett Wilson1f07f20e2017-10-02 18:55:28106#include "base/containers/stack.h"
alex-accc1bde62017-04-19 08:33:55107#include "base/debug/activity_tracker.h"
[email protected]eb4c4d032012-04-03 18:45:05108#include "base/debug/alias.h"
[email protected]58580352010-10-26 04:07:50109#include "base/debug/debugger.h"
110#include "base/debug/stack_trace.h"
Alan Cutter9b0e1ab2019-03-21 04:22:16111#include "base/debug/task_trace.h"
Yannic Bonenberger3dcd7fe2019-06-08 11:01:45112#include "base/no_destructor.h"
Sharon Yanga4b908de2019-05-07 22:19:03113#include "base/path_service.h"
[email protected]2025d002012-11-14 20:54:35114#include "base/posix/eintr_wrapper.h"
[email protected]eb62f7262013-03-30 14:29:00115#include "base/strings/string_piece.h"
Xianzhu Wangae8d96a32018-10-16 20:41:13116#include "base/strings/string_split.h"
[email protected]c914d8a2014-04-23 01:11:01117#include "base/strings/string_util.h"
118#include "base/strings/stringprintf.h"
mark4c7449c2015-11-10 19:53:42119#include "base/strings/sys_string_conversions.h"
[email protected]a4ea1f12013-06-07 18:37:07120#include "base/strings/utf_string_conversions.h"
Benoit Lize5c98a832020-07-07 16:32:01121#include "base/synchronization/lock.h"
Yuta Hijikata9b7279a2020-08-26 16:10:54122#include "base/test/scoped_logging_settings.h"
[email protected]63e66802012-01-18 21:21:09123#include "base/threading/platform_thread.h"
[email protected]99b7c57f2010-09-29 19:26:36124#include "base/vlog.h"
Yuta Hijikata000df18f2020-11-18 06:55:58125#include "build/chromeos_buildflags.h"
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39126
Cliff Smolinskyc5c52102019-05-03 20:51:54127#if defined(OS_WIN)
128#include "base/win/win_util.h"
129#endif
130
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39131#if defined(OS_POSIX) || defined(OS_FUCHSIA)
brettw6ee6fd62015-06-09 18:05:24132#include "base/posix/safe_strerror.h"
[email protected]53c7ce42010-12-14 16:20:04133#endif
[email protected]52a261f2009-03-03 15:01:12134
Yuta Hijikata000df18f2020-11-18 06:55:58135#if BUILDFLAG(IS_CHROMEOS_ASH)
Robbie McElrath8bf49842019-08-20 22:22:53136#include "base/files/scoped_file.h"
137#endif
138
initial.commitd7cae122008-07-26 21:49:38139namespace logging {
140
[email protected]064aa162011-12-03 00:30:08141namespace {
142
thestig3e4787d2015-05-19 19:31:52143VlogInfo* g_vlog_info = nullptr;
144VlogInfo* g_vlog_info_prev = nullptr;
initial.commitd7cae122008-07-26 21:49:38145
weza245bd072017-06-18 23:26:34146const char* const log_severity_names[] = {"INFO", "WARNING", "ERROR", "FATAL"};
Lei Zhang93dd42572020-10-23 18:45:53147static_assert(LOGGING_NUM_SEVERITIES == base::size(log_severity_names),
weza245bd072017-06-18 23:26:34148 "Incorrect number of log_severity_names");
initial.commitd7cae122008-07-26 21:49:38149
thestig75f87352014-12-03 21:42:27150const char* log_severity_name(int severity) {
Lei Zhang93dd42572020-10-23 18:45:53151 if (severity >= 0 && severity < LOGGING_NUM_SEVERITIES)
[email protected]80f360a2014-01-23 01:36:19152 return log_severity_names[severity];
153 return "UNKNOWN";
154}
155
thestig3e4787d2015-05-19 19:31:52156int g_min_log_level = 0;
[email protected]1d8c2702008-08-19 23:39:32157
Sharon Yang7cb919a2019-05-20 20:27:15158// Specifies the process' logging sink(s), represented as a combination of
159// LoggingDestination values joined by bitwise OR.
160int g_logging_destination = LOG_DEFAULT;
initial.commitd7cae122008-07-26 21:49:38161
Yuta Hijikata000df18f2020-11-18 06:55:58162#if BUILDFLAG(IS_CHROMEOS_ASH)
Yuta Hijikata1fc8f6342020-09-01 03:25:56163// Specifies the format of log header for chrome os.
164LogFormat g_log_format = LogFormat::LOG_FORMAT_SYSLOG;
Yuta Hijikata9b7279a2020-08-26 16:10:54165#endif
166
Lei Zhang93dd42572020-10-23 18:45:53167// For LOGGING_ERROR and above, always print to stderr.
168const int kAlwaysPrintErrorLevel = LOGGING_ERROR;
[email protected]a33c9892008-08-25 20:10:31169
[email protected]614e9fa2008-08-11 22:52:59170// Which log file to use? This is initialized by InitLogging or
initial.commitd7cae122008-07-26 21:49:38171// will be lazily initialized to the default value when it is
172// first needed.
jdoerrie5c4dc4e2019-02-01 18:02:33173using PathString = base::FilePath::StringType;
thestig3e4787d2015-05-19 19:31:52174PathString* g_log_file_name = nullptr;
initial.commitd7cae122008-07-26 21:49:38175
thestig3e4787d2015-05-19 19:31:52176// This file is lazily opened and the handle may be nullptr
177FileHandle g_log_file = nullptr;
initial.commitd7cae122008-07-26 21:49:38178
thestig3e4787d2015-05-19 19:31:52179// What should be prepended to each message?
180bool g_log_process_id = false;
181bool g_log_thread_id = false;
182bool g_log_timestamp = true;
183bool g_log_tickcount = false;
James Cooka0536c32018-08-01 20:13:31184const char* g_log_prefix = nullptr;
initial.commitd7cae122008-07-26 21:49:38185
[email protected]81e0a852010-08-17 00:38:12186// Should we pop up fatal debug messages in a dialog?
187bool show_error_dialogs = false;
188
initial.commitd7cae122008-07-26 21:49:38189// An assert handler override specified by the client to be called instead of
alex-accc1bde62017-04-19 08:33:55190// the debug message dialog and process termination. Assert handlers are stored
191// in stack to allow overriding and restoring.
Yannic Bonenberger3dcd7fe2019-06-08 11:01:45192base::stack<LogAssertHandlerFunction>& GetLogAssertHandlerStack() {
193 static base::NoDestructor<base::stack<LogAssertHandlerFunction>> instance;
194 return *instance;
195}
alex-accc1bde62017-04-19 08:33:55196
[email protected]2b07b8412009-11-25 15:26:34197// A log message handler that gets notified of every log message we process.
thestig3e4787d2015-05-19 19:31:52198LogMessageHandlerFunction log_message_handler = nullptr;
initial.commitd7cae122008-07-26 21:49:38199
avi9b6f42932015-12-26 22:15:14200uint64_t TickCount() {
[email protected]f8588472008-11-05 23:17:24201#if defined(OS_WIN)
202 return GetTickCount();
Wezb0501302018-03-09 05:18:45203#elif defined(OS_FUCHSIA)
Sharon Yang52c60992019-05-16 22:41:35204 return zx_clock_get_monotonic() /
Wezb0501302018-03-09 05:18:45205 static_cast<zx_time_t>(base::Time::kNanosecondsPerMicrosecond);
Avi Drissman5b286372020-07-28 21:59:38206#elif defined(OS_APPLE)
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39207 return mach_absolute_time();
[email protected]19ea84ca2010-11-12 08:37:08208#elif defined(OS_NACL)
209 // NaCl sadly does not have _POSIX_TIMERS enabled in sys/features.h
210 // So we have to use clock() for now.
211 return clock();
[email protected]e43eddf12009-12-29 00:32:52212#elif defined(OS_POSIX)
[email protected]052f1b52008-11-06 21:43:07213 struct timespec ts;
214 clock_gettime(CLOCK_MONOTONIC, &ts);
215
avi9b6f42932015-12-26 22:15:14216 uint64_t absolute_micro = static_cast<int64_t>(ts.tv_sec) * 1000000 +
217 static_cast<int64_t>(ts.tv_nsec) / 1000;
[email protected]052f1b52008-11-06 21:43:07218
219 return absolute_micro;
[email protected]f8588472008-11-05 23:17:24220#endif
221}
222
[email protected]614e9fa2008-08-11 22:52:59223void DeleteFilePath(const PathString& log_name) {
[email protected]f6abeba2008-08-08 13:27:28224#if defined(OS_WIN)
Jan Wilken Dörrieb630aca2019-12-04 10:59:11225 DeleteFile(log_name.c_str());
thestig75f87352014-12-03 21:42:27226#elif defined(OS_NACL)
[email protected]ac07ec52013-04-22 17:32:45227 // Do nothing; unlink() isn't supported on NaCl.
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39228#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
[email protected]614e9fa2008-08-11 22:52:59229 unlink(log_name.c_str());
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39230#else
231#error Unsupported platform
[email protected]f6abeba2008-08-08 13:27:28232#endif
233}
initial.commitd7cae122008-07-26 21:49:38234
[email protected]5f95d532010-10-01 17:16:58235PathString GetDefaultLogFile() {
[email protected]5b84fe32010-09-14 22:24:55236#if defined(OS_WIN)
237 // On Windows we use the same path as the exe.
Jan Wilken Dörrieb630aca2019-12-04 10:59:11238 wchar_t module_name[MAX_PATH];
239 GetModuleFileName(nullptr, module_name, MAX_PATH);
[email protected]5f95d532010-10-01 17:16:58240
scottmgfc5b7072015-01-27 21:46:28241 PathString log_name = module_name;
242 PathString::size_type last_backslash = log_name.rfind('\\', log_name.size());
[email protected]5f95d532010-10-01 17:16:58243 if (last_backslash != PathString::npos)
scottmgfc5b7072015-01-27 21:46:28244 log_name.erase(last_backslash + 1);
Jan Wilken Dörrieb630aca2019-12-04 10:59:11245 log_name += FILE_PATH_LITERAL("debug.log");
scottmgfc5b7072015-01-27 21:46:28246 return log_name;
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39247#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
[email protected]5b84fe32010-09-14 22:24:55248 // On other platforms we just use the current directory.
[email protected]5f95d532010-10-01 17:16:58249 return PathString("debug.log");
[email protected]5b84fe32010-09-14 22:24:55250#endif
251}
252
ananta61762fb2015-09-18 01:00:09253// We don't need locks on Windows for atomically appending to files. The OS
254// provides this functionality.
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39255#if defined(OS_POSIX) || defined(OS_FUCHSIA)
[email protected]5b84fe32010-09-14 22:24:55256
Benoit Lize5c98a832020-07-07 16:32:01257base::Lock& GetLoggingLock() {
258 static base::NoDestructor<base::Lock> lock;
259 return *lock;
260}
[email protected]5b84fe32010-09-14 22:24:55261
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39262#endif // OS_POSIX || OS_FUCHSIA
ananta61762fb2015-09-18 01:00:09263
thestig3e4787d2015-05-19 19:31:52264// Called by logging functions to ensure that |g_log_file| is initialized
initial.commitd7cae122008-07-26 21:49:38265// and can be used for writing. Returns false if the file could not be
thestig3e4787d2015-05-19 19:31:52266// initialized. |g_log_file| will be nullptr in this case.
initial.commitd7cae122008-07-26 21:49:38267bool InitializeLogFileHandle() {
thestig3e4787d2015-05-19 19:31:52268 if (g_log_file)
initial.commitd7cae122008-07-26 21:49:38269 return true;
270
thestig3e4787d2015-05-19 19:31:52271 if (!g_log_file_name) {
[email protected]614e9fa2008-08-11 22:52:59272 // Nobody has called InitLogging to specify a debug log file, so here we
273 // initialize the log file name to a default.
thestig3e4787d2015-05-19 19:31:52274 g_log_file_name = new PathString(GetDefaultLogFile());
initial.commitd7cae122008-07-26 21:49:38275 }
276
Robbie McElrath8bf49842019-08-20 22:22:53277 if ((g_logging_destination & LOG_TO_FILE) == 0)
278 return true;
279
[email protected]614e9fa2008-08-11 22:52:59280#if defined(OS_WIN)
Robbie McElrath8bf49842019-08-20 22:22:53281 // The FILE_APPEND_DATA access mask ensures that the file is atomically
282 // appended to across accesses from multiple threads.
283 // https://msdn.microsoft.com/en-us/library/windows/desktop/aa364399(v=vs.85).aspx
284 // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx
Jan Wilken Dörrieb630aca2019-12-04 10:59:11285 g_log_file = CreateFile(g_log_file_name->c_str(), FILE_APPEND_DATA,
Robbie McElrath8bf49842019-08-20 22:22:53286 FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
287 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
288 if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) {
289 // We are intentionally not using FilePath or FileUtil here to reduce the
290 // dependencies of the logging implementation. For e.g. FilePath and
291 // FileUtil depend on shell32 and user32.dll. This is not acceptable for
292 // some consumers of base logging like chrome_elf, etc.
293 // Please don't change the code below to use FilePath.
294 // try the current directory
Jan Wilken Dörrieb630aca2019-12-04 10:59:11295 wchar_t system_buffer[MAX_PATH];
Robbie McElrath8bf49842019-08-20 22:22:53296 system_buffer[0] = 0;
Jan Wilken Dörrieb630aca2019-12-04 10:59:11297 DWORD len = ::GetCurrentDirectory(base::size(system_buffer), system_buffer);
Robbie McElrath8bf49842019-08-20 22:22:53298 if (len == 0 || len > base::size(system_buffer))
299 return false;
300
301 *g_log_file_name = system_buffer;
302 // Append a trailing backslash if needed.
303 if (g_log_file_name->back() != L'\\')
Jan Wilken Dörrieb630aca2019-12-04 10:59:11304 *g_log_file_name += FILE_PATH_LITERAL("\\");
305 *g_log_file_name += FILE_PATH_LITERAL("debug.log");
Robbie McElrath8bf49842019-08-20 22:22:53306
Jan Wilken Dörrieb630aca2019-12-04 10:59:11307 g_log_file = CreateFile(g_log_file_name->c_str(), FILE_APPEND_DATA,
thestig3e4787d2015-05-19 19:31:52308 FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
309 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
310 if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) {
Robbie McElrath8bf49842019-08-20 22:22:53311 g_log_file = nullptr;
[email protected]78c6dd62009-06-08 23:29:11312 return false;
Robbie McElrath8bf49842019-08-20 22:22:53313 }
314 }
315#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
316 g_log_file = fopen(g_log_file_name->c_str(), "a");
317 if (g_log_file == nullptr)
318 return false;
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39319#else
320#error Unsupported platform
[email protected]f6abeba2008-08-08 13:27:28321#endif
[email protected]1d8c2702008-08-19 23:39:32322
initial.commitd7cae122008-07-26 21:49:38323 return true;
324}
325
[email protected]17dcf752013-07-15 21:47:09326void CloseFile(FileHandle log) {
327#if defined(OS_WIN)
328 CloseHandle(log);
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39329#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
[email protected]17dcf752013-07-15 21:47:09330 fclose(log);
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39331#else
332#error Unsupported platform
[email protected]17dcf752013-07-15 21:47:09333#endif
334}
335
336void CloseLogFileUnlocked() {
thestig3e4787d2015-05-19 19:31:52337 if (!g_log_file)
[email protected]17dcf752013-07-15 21:47:09338 return;
339
thestig3e4787d2015-05-19 19:31:52340 CloseFile(g_log_file);
341 g_log_file = nullptr;
Robbie McElrath8bf49842019-08-20 22:22:53342
343 // If we initialized logging via an externally-provided file descriptor, we
344 // won't have a log path set and shouldn't try to reopen the log file.
345 if (!g_log_file_name)
346 g_logging_destination &= ~LOG_TO_FILE;
[email protected]17dcf752013-07-15 21:47:09347}
348
[email protected]064aa162011-12-03 00:30:08349} // namespace
350
Tomas Popelaafffa972018-11-13 20:42:05351#if defined(DCHECK_IS_CONFIGURABLE)
Lei Zhang93dd42572020-10-23 18:45:53352// In DCHECK-enabled Chrome builds, allow the meaning of LOGGING_DCHECK to be
Wez289477f2017-08-24 20:51:30353// determined at run-time. We default it to INFO, to avoid it triggering
354// crashes before the run-time has explicitly chosen the behaviour.
Lei Zhang93dd42572020-10-23 18:45:53355BASE_EXPORT logging::LogSeverity LOGGING_DCHECK = LOGGING_INFO;
Tomas Popelaafffa972018-11-13 20:42:05356#endif // defined(DCHECK_IS_CONFIGURABLE)
Wez289477f2017-08-24 20:51:30357
scottmg3c957a52016-12-10 20:57:59358// This is never instantiated, it's just used for EAT_STREAM_PARAMETERS to have
359// an object of the correct type on the LHS of the unused part of the ternary
360// operator.
361std::ostream* g_swallow_stream;
362
[email protected]5e3f7c22013-06-21 21:15:33363bool BaseInitLoggingImpl(const LoggingSettings& settings) {
[email protected]ac07ec52013-04-22 17:32:45364#if defined(OS_NACL)
Sharon Yang7cb919a2019-05-20 20:27:15365 // Can log only to the system debug log and stderr.
366 CHECK_EQ(settings.logging_dest & ~(LOG_TO_SYSTEM_DEBUG_LOG | LOG_TO_STDERR),
367 0u);
[email protected]ac07ec52013-04-22 17:32:45368#endif
Robbie McElrath8bf49842019-08-20 22:22:53369
Yuta Hijikata000df18f2020-11-18 06:55:58370#if BUILDFLAG(IS_CHROMEOS_ASH)
Yuta Hijikata8a93e522020-09-25 08:59:57371 g_log_format = settings.log_format;
372#endif
373
Joshua Peraza236556ce2020-10-22 23:23:31374 if (base::CommandLine::InitializedForCurrentProcess()) {
375 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
376 // Don't bother initializing |g_vlog_info| unless we use one of the
377 // vlog switches.
378 if (command_line->HasSwitch(switches::kV) ||
379 command_line->HasSwitch(switches::kVModule)) {
380 // NOTE: If |g_vlog_info| has already been initialized, it might be in use
381 // by another thread. Don't delete the old VLogInfo, just create a second
382 // one. We keep track of both to avoid memory leak warnings.
383 CHECK(!g_vlog_info_prev);
384 g_vlog_info_prev = g_vlog_info;
[email protected]064aa162011-12-03 00:30:08385
Joshua Peraza236556ce2020-10-22 23:23:31386 g_vlog_info =
387 new VlogInfo(command_line->GetSwitchValueASCII(switches::kV),
388 command_line->GetSwitchValueASCII(switches::kVModule),
389 &g_min_log_level);
390 }
[email protected]99b7c57f2010-09-29 19:26:36391 }
392
thestig3e4787d2015-05-19 19:31:52393 g_logging_destination = settings.logging_dest;
initial.commitd7cae122008-07-26 21:49:38394
Wez224c0bf62019-05-24 19:26:13395#if defined(OS_FUCHSIA)
396 if (g_logging_destination & LOG_TO_SYSTEM_DEBUG_LOG) {
Joshua Peraza236556ce2020-10-22 23:23:31397 std::string log_tag = base::CommandLine::ForCurrentProcess()
398 ->GetProgram()
399 .BaseName()
400 .AsUTF8Unsafe();
Wez224c0bf62019-05-24 19:26:13401 const char* log_tag_data = log_tag.data();
David Dorwin595d7f62020-11-04 00:04:36402
403 fx_logger_config_t config = {
404 .min_severity = FX_LOG_INFO,
405 .console_fd = -1,
David Dorwin595d7f62020-11-04 00:04:36406 .tags = &log_tag_data,
407 .num_tags = 1,
408 };
Wez0e6cefc2020-04-21 18:04:47409 fx_log_reconfigure(&config);
Wez224c0bf62019-05-24 19:26:13410 }
411#endif
412
[email protected]5e3f7c22013-06-21 21:15:33413 // ignore file options unless logging to file is set.
thestig3e4787d2015-05-19 19:31:52414 if ((g_logging_destination & LOG_TO_FILE) == 0)
[email protected]c7d5da992010-10-28 00:20:21415 return true;
initial.commitd7cae122008-07-26 21:49:38416
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39417#if defined(OS_POSIX) || defined(OS_FUCHSIA)
Benoit Lize5c98a832020-07-07 16:32:01418 base::AutoLock guard(GetLoggingLock());
ananta61762fb2015-09-18 01:00:09419#endif
[email protected]17dcf752013-07-15 21:47:09420
421 // Calling InitLogging twice or after some log call has already opened the
422 // default log file will re-initialize to the new options.
423 CloseLogFileUnlocked();
424
Yuta Hijikata000df18f2020-11-18 06:55:58425#if BUILDFLAG(IS_CHROMEOS_ASH)
Robbie McElrath8bf49842019-08-20 22:22:53426 if (settings.log_file) {
427 DCHECK(!settings.log_file_path);
428 g_log_file = settings.log_file;
429 return true;
430 }
431#endif
Lei Zhang93dd42572020-10-23 18:45:53432
Xiaohan Wang5411974b2020-10-10 19:36:12433 DCHECK(settings.log_file_path) << "LOG_TO_FILE set but no log_file_path!";
Robbie McElrath8bf49842019-08-20 22:22:53434
thestig3e4787d2015-05-19 19:31:52435 if (!g_log_file_name)
436 g_log_file_name = new PathString();
Robbie McElrath8bf49842019-08-20 22:22:53437 *g_log_file_name = settings.log_file_path;
[email protected]5e3f7c22013-06-21 21:15:33438 if (settings.delete_old == DELETE_OLD_LOG_FILE)
thestig3e4787d2015-05-19 19:31:52439 DeleteFilePath(*g_log_file_name);
initial.commitd7cae122008-07-26 21:49:38440
[email protected]c7d5da992010-10-28 00:20:21441 return InitializeLogFileHandle();
initial.commitd7cae122008-07-26 21:49:38442}
443
444void SetMinLogLevel(int level) {
Lei Zhang93dd42572020-10-23 18:45:53445 g_min_log_level = std::min(LOGGING_FATAL, level);
initial.commitd7cae122008-07-26 21:49:38446}
447
448int GetMinLogLevel() {
thestig3e4787d2015-05-19 19:31:52449 return g_min_log_level;
initial.commitd7cae122008-07-26 21:49:38450}
451
skobesc78c0ad72015-12-07 20:21:23452bool ShouldCreateLogMessage(int severity) {
453 if (severity < g_min_log_level)
454 return false;
455
Wez6c8acb82019-07-18 00:32:59456 // Return true here unless we know ~LogMessage won't do anything.
skobesc78c0ad72015-12-07 20:21:23457 return g_logging_destination != LOG_NONE || log_message_handler ||
458 severity >= kAlwaysPrintErrorLevel;
459}
460
Wez6c8acb82019-07-18 00:32:59461// Returns true when LOG_TO_STDERR flag is set, or |severity| is high.
462// If |severity| is high then true will be returned when no log destinations are
463// set, or only LOG_TO_FILE is set, since that is useful for local development
464// and debugging.
465bool ShouldLogToStderr(int severity) {
466 if (g_logging_destination & LOG_TO_STDERR)
467 return true;
468 if (severity >= kAlwaysPrintErrorLevel)
469 return (g_logging_destination & ~LOG_TO_FILE) == LOG_NONE;
470 return false;
471}
472
[email protected]162ac0f2010-11-04 15:50:49473int GetVlogVerbosity() {
474 return std::max(-1, LOG_INFO - GetMinLogLevel());
475}
476
[email protected]99b7c57f2010-09-29 19:26:36477int GetVlogLevelHelper(const char* file, size_t N) {
478 DCHECK_GT(N, 0U);
thestig3e4787d2015-05-19 19:31:52479 // Note: |g_vlog_info| may change on a different thread during startup
480 // (but will always be valid or nullptr).
[email protected]064aa162011-12-03 00:30:08481 VlogInfo* vlog_info = g_vlog_info;
482 return vlog_info ?
483 vlog_info->GetVlogLevel(base::StringPiece(file, N - 1)) :
[email protected]162ac0f2010-11-04 15:50:49484 GetVlogVerbosity();
[email protected]99b7c57f2010-09-29 19:26:36485}
486
initial.commitd7cae122008-07-26 21:49:38487void SetLogItems(bool enable_process_id, bool enable_thread_id,
488 bool enable_timestamp, bool enable_tickcount) {
thestig3e4787d2015-05-19 19:31:52489 g_log_process_id = enable_process_id;
490 g_log_thread_id = enable_thread_id;
491 g_log_timestamp = enable_timestamp;
492 g_log_tickcount = enable_tickcount;
initial.commitd7cae122008-07-26 21:49:38493}
494
James Cooka0536c32018-08-01 20:13:31495void SetLogPrefix(const char* prefix) {
496 DCHECK(!prefix ||
497 base::ContainsOnlyChars(prefix, "abcdefghijklmnopqrstuvwxyz"));
498 g_log_prefix = prefix;
499}
500
[email protected]81e0a852010-08-17 00:38:12501void SetShowErrorDialogs(bool enable_dialogs) {
502 show_error_dialogs = enable_dialogs;
503}
504
alex-accc1bde62017-04-19 08:33:55505ScopedLogAssertHandler::ScopedLogAssertHandler(
506 LogAssertHandlerFunction handler) {
Yannic Bonenberger3dcd7fe2019-06-08 11:01:45507 GetLogAssertHandlerStack().push(std::move(handler));
alex-accc1bde62017-04-19 08:33:55508}
509
510ScopedLogAssertHandler::~ScopedLogAssertHandler() {
Yannic Bonenberger3dcd7fe2019-06-08 11:01:45511 GetLogAssertHandlerStack().pop();
initial.commitd7cae122008-07-26 21:49:38512}
513
[email protected]2b07b8412009-11-25 15:26:34514void SetLogMessageHandler(LogMessageHandlerFunction handler) {
515 log_message_handler = handler;
516}
517
[email protected]64e5cc02010-11-03 19:20:27518LogMessageHandlerFunction GetLogMessageHandler() {
519 return log_message_handler;
520}
521
[email protected]f2c05492014-06-17 12:04:23522#if !defined(NDEBUG)
[email protected]d81baca42010-03-01 13:10:22523// Displays a message box to the user with the error message in it.
524// Used for fatal messages, where we close the app simultaneously.
[email protected]561513f2010-12-16 23:29:25525// This is for developers only; we don't use this in circumstances
526// (like release builds) where users could see it, since users don't
527// understand these messages anyway.
[email protected]d81baca42010-03-01 13:10:22528void DisplayDebugMessageInDialog(const std::string& str) {
initial.commitd7cae122008-07-26 21:49:38529 if (str.empty())
530 return;
531
[email protected]81e0a852010-08-17 00:38:12532 if (!show_error_dialogs)
[email protected]846ed9c32010-07-29 20:33:44533 return;
534
[email protected]f6abeba2008-08-08 13:27:28535#if defined(OS_WIN)
[email protected]561513f2010-12-16 23:29:25536 // We intentionally don't implement a dialog on other platforms.
537 // You can just look at stderr.
Cliff Smolinskyc5c52102019-05-03 20:51:54538 if (base::win::IsUser32AndGdi32Available()) {
539 MessageBoxW(nullptr, base::as_wcstr(base::UTF8ToUTF16(str)), L"Fatal error",
540 MB_OK | MB_ICONHAND | MB_TOPMOST);
541 } else {
542 OutputDebugStringW(base::as_wcstr(base::UTF8ToUTF16(str)));
543 }
thestig3e4787d2015-05-19 19:31:52544#endif // defined(OS_WIN)
initial.commitd7cae122008-07-26 21:49:38545}
[email protected]f2c05492014-06-17 12:04:23546#endif // !defined(NDEBUG)
initial.commitd7cae122008-07-26 21:49:38547
[email protected]eae9c062011-01-11 00:50:59548LogMessage::LogMessage(const char* file, int line, LogSeverity severity)
549 : severity_(severity), file_(file), line_(line) {
550 Init(file, line);
551}
552
tnagel4a045d3f2015-07-12 14:19:28553LogMessage::LogMessage(const char* file, int line, const char* condition)
Lei Zhang93dd42572020-10-23 18:45:53554 : severity_(LOGGING_FATAL), file_(file), line_(line) {
tnagel4a045d3f2015-07-12 14:19:28555 Init(file, line);
556 stream_ << "Check failed: " << condition << ". ";
557}
558
initial.commitd7cae122008-07-26 21:49:38559LogMessage::~LogMessage() {
alex-accc1bde62017-04-19 08:33:55560 size_t stack_start = stream_.tellp();
rayb0088ee52017-04-26 22:35:08561#if !defined(OFFICIAL_BUILD) && !defined(OS_NACL) && !defined(__UCLIBC__) && \
562 !defined(OS_AIX)
Lei Zhang93dd42572020-10-23 18:45:53563 if (severity_ == LOGGING_FATAL && !base::debug::BeingDebugged()) {
brucedawson7c559eb2015-09-05 00:34:42564 // Include a stack trace on a fatal, unless a debugger is attached.
Alan Cutter9b0e1ab2019-03-21 04:22:16565 base::debug::StackTrace stack_trace;
[email protected]d1ccc35a2010-03-24 05:03:24566 stream_ << std::endl; // Newline to separate from log message.
Alan Cutter9b0e1ab2019-03-21 04:22:16567 stack_trace.OutputToStream(&stream_);
568 base::debug::TaskTrace task_trace;
569 if (!task_trace.empty())
570 task_trace.OutputToStream(&stream_);
Chris Hamilton306740d2019-04-25 18:48:36571
Chris Hamilton888085312019-05-30 00:53:30572 // Include the IPC context, if any.
573 // TODO(chrisha): Integrate with symbolization once those tools exist!
Chris Hamilton306740d2019-04-25 18:48:36574 const auto* task = base::TaskAnnotator::CurrentTaskForThread();
Chris Hamilton888085312019-05-30 00:53:30575 if (task && task->ipc_hash) {
576 stream_ << "IPC message handler context: "
577 << base::StringPrintf("0x%08X", task->ipc_hash) << std::endl;
Chris Hamilton306740d2019-04-25 18:48:36578 }
[email protected]d1ccc35a2010-03-24 05:03:24579 }
[email protected]1d8c2702008-08-19 23:39:32580#endif
[email protected]d1ccc35a2010-03-24 05:03:24581 stream_ << std::endl;
582 std::string str_newline(stream_.str());
Nicolò Mazzucato6c278d9b2019-08-02 16:25:44583 TRACE_LOG_MESSAGE(
584 file_, base::StringPiece(str_newline).substr(message_start_), line_);
[email protected]d1ccc35a2010-03-24 05:03:24585
[email protected]2b07b8412009-11-25 15:26:34586 // Give any log message handler first dibs on the message.
[email protected]5e3f7c22013-06-21 21:15:33587 if (log_message_handler &&
588 log_message_handler(severity_, file_, line_,
589 message_start_, str_newline)) {
[email protected]162ac0f2010-11-04 15:50:49590 // The handler took care of it, no further processing.
[email protected]2b07b8412009-11-25 15:26:34591 return;
[email protected]162ac0f2010-11-04 15:50:49592 }
initial.commitd7cae122008-07-26 21:49:38593
thestig3e4787d2015-05-19 19:31:52594 if ((g_logging_destination & LOG_TO_SYSTEM_DEBUG_LOG) != 0) {
[email protected]f6abeba2008-08-08 13:27:28595#if defined(OS_WIN)
initial.commitd7cae122008-07-26 21:49:38596 OutputDebugStringA(str_newline.c_str());
Avi Drissman5b286372020-07-28 21:59:38597#elif defined(OS_APPLE)
mark4c7449c2015-11-10 19:53:42598 // In LOG_TO_SYSTEM_DEBUG_LOG mode, log messages are always written to
Eric Noyaufce100702017-10-16 09:46:34599 // stderr. If stderr is /dev/null, also log via ASL (Apple System Log) or
600 // its successor OS_LOG. If there's something weird about stderr, assume
601 // that log messages are going nowhere and log via ASL/OS_LOG too.
602 // Messages logged via ASL/OS_LOG show up in Console.app.
mark4c7449c2015-11-10 19:53:42603 //
604 // Programs started by launchd, as UI applications normally are, have had
605 // stderr connected to /dev/null since OS X 10.8. Prior to that, stderr was
606 // a pipe to launchd, which logged what it received (see log_redirect_fd in
607 // 10.7.5 launchd-392.39/launchd/src/launchd_core_logic.c).
608 //
609 // Another alternative would be to determine whether stderr is a pipe to
610 // launchd and avoid logging via ASL only in that case. See 10.7.5
611 // CF-635.21/CFUtilities.c also_do_stderr(). This would result in logging to
Eric Noyaufce100702017-10-16 09:46:34612 // both stderr and ASL/OS_LOG even in tests, where it's undesirable to log
613 // to the system log at all.
mark4c7449c2015-11-10 19:53:42614 //
615 // Note that the ASL client by default discards messages whose levels are
616 // below ASL_LEVEL_NOTICE. It's possible to change that with
617 // asl_set_filter(), but this is pointless because syslogd normally applies
618 // the same filter.
Eric Noyaufce100702017-10-16 09:46:34619 const bool log_to_system = []() {
mark4c7449c2015-11-10 19:53:42620 struct stat stderr_stat;
621 if (fstat(fileno(stderr), &stderr_stat) == -1) {
622 return true;
623 }
624 if (!S_ISCHR(stderr_stat.st_mode)) {
625 return false;
626 }
627
628 struct stat dev_null_stat;
629 if (stat(_PATH_DEVNULL, &dev_null_stat) == -1) {
630 return true;
631 }
632
633 return !S_ISCHR(dev_null_stat.st_mode) ||
634 stderr_stat.st_rdev == dev_null_stat.st_rdev;
635 }();
636
Eric Noyaufce100702017-10-16 09:46:34637 if (log_to_system) {
mark4c7449c2015-11-10 19:53:42638 // Log roughly the same way that CFLog() and NSLog() would. See 10.10.5
639 // CF-1153.18/CFUtilities.c __CFLogCString().
mark4c7449c2015-11-10 19:53:42640 CFBundleRef main_bundle = CFBundleGetMainBundle();
641 CFStringRef main_bundle_id_cf =
642 main_bundle ? CFBundleGetIdentifier(main_bundle) : nullptr;
Eric Noyaufce100702017-10-16 09:46:34643 std::string main_bundle_id =
mark4c7449c2015-11-10 19:53:42644 main_bundle_id_cf ? base::SysCFStringRefToUTF8(main_bundle_id_cf)
Eric Noyaufce100702017-10-16 09:46:34645 : std::string("");
646#if defined(USE_ASL)
647 // The facility is set to the main bundle ID if available. Otherwise,
648 // "com.apple.console" is used.
649 const class ASLClient {
mark4c7449c2015-11-10 19:53:42650 public:
Bruce Dawson4c6f8e12017-11-16 04:35:59651 explicit ASLClient(const std::string& facility)
652 : client_(asl_open(nullptr, facility.c_str(), ASL_OPT_NO_DELAY)) {}
David Bienvenub4b441e2020-09-23 05:49:57653 ASLClient(const ASLClient&) = delete;
654 ASLClient& operator=(const ASLClient&) = delete;
mark4c7449c2015-11-10 19:53:42655 ~ASLClient() { asl_close(client_); }
656
657 aslclient get() const { return client_; }
658
659 private:
660 aslclient client_;
Eric Noyaufce100702017-10-16 09:46:34661 } asl_client(main_bundle_id.empty() ? main_bundle_id
662 : "com.apple.console");
mark4c7449c2015-11-10 19:53:42663
Eric Noyaufce100702017-10-16 09:46:34664 const class ASLMessage {
mark4c7449c2015-11-10 19:53:42665 public:
666 ASLMessage() : message_(asl_new(ASL_TYPE_MSG)) {}
David Bienvenub4b441e2020-09-23 05:49:57667 ASLMessage(const ASLMessage&) = delete;
668 ASLMessage& operator=(const ASLMessage&) = delete;
mark4c7449c2015-11-10 19:53:42669 ~ASLMessage() { asl_free(message_); }
670
671 aslmsg get() const { return message_; }
672
673 private:
674 aslmsg message_;
mark4c7449c2015-11-10 19:53:42675 } asl_message;
676
677 // By default, messages are only readable by the admin group. Explicitly
678 // make them readable by the user generating the messages.
679 char euid_string[12];
Avi Drissmane3b70bf2019-01-04 19:50:22680 snprintf(euid_string, base::size(euid_string), "%d", geteuid());
mark4c7449c2015-11-10 19:53:42681 asl_set(asl_message.get(), ASL_KEY_READ_UID, euid_string);
682
683 // Map Chrome log severities to ASL log levels.
684 const char* const asl_level_string = [](LogSeverity severity) {
685 // ASL_LEVEL_* are ints, but ASL needs equivalent strings. This
686 // non-obvious two-step macro trick achieves what's needed.
687 // https://gcc.gnu.org/onlinedocs/cpp/Stringification.html
688#define ASL_LEVEL_STR(level) ASL_LEVEL_STR_X(level)
689#define ASL_LEVEL_STR_X(level) #level
690 switch (severity) {
Lei Zhang93dd42572020-10-23 18:45:53691 case LOGGING_INFO:
mark4c7449c2015-11-10 19:53:42692 return ASL_LEVEL_STR(ASL_LEVEL_INFO);
Lei Zhang93dd42572020-10-23 18:45:53693 case LOGGING_WARNING:
mark4c7449c2015-11-10 19:53:42694 return ASL_LEVEL_STR(ASL_LEVEL_WARNING);
Lei Zhang93dd42572020-10-23 18:45:53695 case LOGGING_ERROR:
mark4c7449c2015-11-10 19:53:42696 return ASL_LEVEL_STR(ASL_LEVEL_ERR);
Lei Zhang93dd42572020-10-23 18:45:53697 case LOGGING_FATAL:
mark4c7449c2015-11-10 19:53:42698 return ASL_LEVEL_STR(ASL_LEVEL_CRIT);
699 default:
700 return severity < 0 ? ASL_LEVEL_STR(ASL_LEVEL_DEBUG)
701 : ASL_LEVEL_STR(ASL_LEVEL_NOTICE);
702 }
703#undef ASL_LEVEL_STR
704#undef ASL_LEVEL_STR_X
705 }(severity_);
706 asl_set(asl_message.get(), ASL_KEY_LEVEL, asl_level_string);
707
708 asl_set(asl_message.get(), ASL_KEY_MSG, str_newline.c_str());
709
710 asl_send(asl_client.get(), asl_message.get());
Eric Noyaufce100702017-10-16 09:46:34711#else // !defined(USE_ASL)
712 const class OSLog {
713 public:
714 explicit OSLog(const char* subsystem)
715 : os_log_(subsystem ? os_log_create(subsystem, "chromium_logging")
716 : OS_LOG_DEFAULT) {}
David Bienvenub4b441e2020-09-23 05:49:57717 OSLog(const OSLog&) = delete;
718 OSLog& operator=(const OSLog&) = delete;
Eric Noyaufce100702017-10-16 09:46:34719 ~OSLog() {
720 if (os_log_ != OS_LOG_DEFAULT) {
721 os_release(os_log_);
722 }
723 }
724 os_log_t get() const { return os_log_; }
725
726 private:
727 os_log_t os_log_;
Eric Noyaufce100702017-10-16 09:46:34728 } log(main_bundle_id.empty() ? nullptr : main_bundle_id.c_str());
729 const os_log_type_t os_log_type = [](LogSeverity severity) {
730 switch (severity) {
Lei Zhang93dd42572020-10-23 18:45:53731 case LOGGING_INFO:
Eric Noyaufce100702017-10-16 09:46:34732 return OS_LOG_TYPE_INFO;
Lei Zhang93dd42572020-10-23 18:45:53733 case LOGGING_WARNING:
Eric Noyaufce100702017-10-16 09:46:34734 return OS_LOG_TYPE_DEFAULT;
Lei Zhang93dd42572020-10-23 18:45:53735 case LOGGING_ERROR:
Eric Noyaufce100702017-10-16 09:46:34736 return OS_LOG_TYPE_ERROR;
Lei Zhang93dd42572020-10-23 18:45:53737 case LOGGING_FATAL:
Eric Noyaufce100702017-10-16 09:46:34738 return OS_LOG_TYPE_FAULT;
739 default:
740 return severity < 0 ? OS_LOG_TYPE_DEBUG : OS_LOG_TYPE_DEFAULT;
741 }
742 }(severity_);
743 os_log_with_type(log.get(), os_log_type, "%{public}s",
744 str_newline.c_str());
745#endif // defined(USE_ASL)
mark4c7449c2015-11-10 19:53:42746 }
[email protected]3132e35c2011-07-07 20:46:50747#elif defined(OS_ANDROID)
[email protected]efbae7da2013-05-21 22:39:25748 android_LogPriority priority =
749 (severity_ < 0) ? ANDROID_LOG_VERBOSE : ANDROID_LOG_UNKNOWN;
[email protected]3132e35c2011-07-07 20:46:50750 switch (severity_) {
Lei Zhang93dd42572020-10-23 18:45:53751 case LOGGING_INFO:
[email protected]3132e35c2011-07-07 20:46:50752 priority = ANDROID_LOG_INFO;
753 break;
Lei Zhang93dd42572020-10-23 18:45:53754 case LOGGING_WARNING:
[email protected]3132e35c2011-07-07 20:46:50755 priority = ANDROID_LOG_WARN;
756 break;
Lei Zhang93dd42572020-10-23 18:45:53757 case LOGGING_ERROR:
[email protected]3132e35c2011-07-07 20:46:50758 priority = ANDROID_LOG_ERROR;
759 break;
Lei Zhang93dd42572020-10-23 18:45:53760 case LOGGING_FATAL:
[email protected]3132e35c2011-07-07 20:46:50761 priority = ANDROID_LOG_FATAL;
762 break;
763 }
Tomasz Śniatowski23dd15af2019-02-15 08:32:03764 const char kAndroidLogTag[] = "chromium";
Xianzhu Wangae8d96a32018-10-16 20:41:13765#if DCHECK_IS_ON()
766 // Split the output by new lines to prevent the Android system from
767 // truncating the log.
Tomasz Śniatowski23dd15af2019-02-15 08:32:03768 std::vector<std::string> lines = base::SplitString(
769 str_newline, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
770 // str_newline has an extra newline appended to it (at the top of this
771 // function), so skip the last split element to avoid needlessly
772 // logging an empty string.
773 lines.pop_back();
774 for (const auto& line : lines)
775 __android_log_write(priority, kAndroidLogTag, line.c_str());
Xianzhu Wangae8d96a32018-10-16 20:41:13776#else
777 // The Android system may truncate the string if it's too long.
Tomasz Śniatowski23dd15af2019-02-15 08:32:03778 __android_log_write(priority, kAndroidLogTag, str_newline.c_str());
[email protected]107bc0f12008-08-26 17:48:18779#endif
Sharon Yanga4b908de2019-05-07 22:19:03780#elif defined(OS_FUCHSIA)
781 fx_log_severity_t severity = FX_LOG_INFO;
Wez224c0bf62019-05-24 19:26:13782 switch (severity_) {
Lei Zhang93dd42572020-10-23 18:45:53783 case LOGGING_INFO:
Sharon Yanga4b908de2019-05-07 22:19:03784 severity = FX_LOG_INFO;
785 break;
Lei Zhang93dd42572020-10-23 18:45:53786 case LOGGING_WARNING:
Sharon Yanga4b908de2019-05-07 22:19:03787 severity = FX_LOG_WARNING;
788 break;
Lei Zhang93dd42572020-10-23 18:45:53789 case LOGGING_ERROR:
Sharon Yanga4b908de2019-05-07 22:19:03790 severity = FX_LOG_ERROR;
791 break;
Lei Zhang93dd42572020-10-23 18:45:53792 case LOGGING_FATAL:
Wez224c0bf62019-05-24 19:26:13793 // Don't use FX_LOG_FATAL, otherwise fx_logger_log() will abort().
794 severity = FX_LOG_ERROR;
Sharon Yanga4b908de2019-05-07 22:19:03795 break;
796 }
797
798 fx_logger_t* logger = fx_log_get_logger();
799 if (logger) {
Kevin Marshall9873826d2019-10-14 20:09:35800 // Temporarily remove the trailing newline from |str_newline|'s C-string
801 // representation, since fx_logger will add a newline of its own.
Wez224c0bf62019-05-24 19:26:13802 str_newline.pop_back();
Samane1a69122020-11-06 16:52:19803 fx_logger_log_with_source(logger, severity, nullptr, file_, line_,
804 str_newline.c_str() + message_start_);
Wez224c0bf62019-05-24 19:26:13805 str_newline.push_back('\n');
Sharon Yanga4b908de2019-05-07 22:19:03806 }
807#endif // OS_FUCHSIA
Sharon Yang7cb919a2019-05-20 20:27:15808 }
809
Wez6c8acb82019-07-18 00:32:59810 if (ShouldLogToStderr(severity_)) {
[email protected]51105382014-03-14 17:02:15811 ignore_result(fwrite(str_newline.data(), str_newline.size(), 1, stderr));
[email protected]1ce41052009-12-02 00:34:02812 fflush(stderr);
[email protected]f6abeba2008-08-08 13:27:28813 }
[email protected]52a261f2009-03-03 15:01:12814
thestig3e4787d2015-05-19 19:31:52815 if ((g_logging_destination & LOG_TO_FILE) != 0) {
[email protected]17dcf752013-07-15 21:47:09816 // We can have multiple threads and/or processes, so try to prevent them
817 // from clobbering each other's writes.
818 // If the client app did not call InitLogging, and the lock has not
819 // been created do it now. We do this on demand, but if two threads try
820 // to do this at the same time, there will be a race condition to create
821 // the lock. This is why InitLogging should be called from the main
822 // thread at the beginning of execution.
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39823#if defined(OS_POSIX) || defined(OS_FUCHSIA)
Benoit Lize5c98a832020-07-07 16:32:01824 base::AutoLock guard(GetLoggingLock());
ananta61762fb2015-09-18 01:00:09825#endif
[email protected]5b84fe32010-09-14 22:24:55826 if (InitializeLogFileHandle()) {
[email protected]f6abeba2008-08-08 13:27:28827#if defined(OS_WIN)
[email protected]5b84fe32010-09-14 22:24:55828 DWORD num_written;
thestig3e4787d2015-05-19 19:31:52829 WriteFile(g_log_file,
[email protected]5b84fe32010-09-14 22:24:55830 static_cast<const void*>(str_newline.c_str()),
831 static_cast<DWORD>(str_newline.length()),
832 &num_written,
thestig3e4787d2015-05-19 19:31:52833 nullptr);
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39834#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
[email protected]51105382014-03-14 17:02:15835 ignore_result(fwrite(
thestig3e4787d2015-05-19 19:31:52836 str_newline.data(), str_newline.size(), 1, g_log_file));
837 fflush(g_log_file);
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39838#else
839#error Unsupported platform
[email protected]cba21962010-08-31 22:35:55840#endif
initial.commitd7cae122008-07-26 21:49:38841 }
842 }
843
Lei Zhang93dd42572020-10-23 18:45:53844 if (severity_ == LOGGING_FATAL) {
bcwhite7a30eb42016-12-02 21:23:40845 // Write the log message to the global activity tracker, if running.
846 base::debug::GlobalActivityTracker* tracker =
847 base::debug::GlobalActivityTracker::Get();
848 if (tracker)
849 tracker->RecordLogMessage(str_newline);
850
Wezd78fee62020-09-11 18:29:14851 char str_stack[1024];
852 base::strlcpy(str_stack, str_newline.data(), base::size(str_stack));
Weze976b732018-10-20 03:37:31853 base::debug::Alias(&str_stack);
[email protected]eb4c4d032012-04-03 18:45:05854
Yannic Bonenberger3dcd7fe2019-06-08 11:01:45855 if (!GetLogAssertHandlerStack().empty()) {
alex-accc1bde62017-04-19 08:33:55856 LogAssertHandlerFunction log_assert_handler =
Yannic Bonenberger3dcd7fe2019-06-08 11:01:45857 GetLogAssertHandlerStack().top();
alex-accc1bde62017-04-19 08:33:55858
859 if (log_assert_handler) {
860 log_assert_handler.Run(
861 file_, line_,
862 base::StringPiece(str_newline.c_str() + message_start_,
863 stack_start - message_start_),
864 base::StringPiece(str_newline.c_str() + stack_start));
865 }
[email protected]1ffe08c12008-08-13 11:15:11866 } else {
[email protected]82d89ab2014-02-28 18:25:34867 // Don't use the string with the newline, get a fresh version to send to
868 // the debug message process. We also don't display assertions to the
869 // user in release mode. The enduser can't do anything with this
870 // information, and displaying message boxes when the application is
871 // hosed can cause additional problems.
[email protected]4d5901272008-11-06 00:33:50872#ifndef NDEBUG
brucedawson7c559eb2015-09-05 00:34:42873 if (!base::debug::BeingDebugged()) {
874 // Displaying a dialog is unnecessary when debugging and can complicate
875 // debugging.
876 DisplayDebugMessageInDialog(stream_.str());
877 }
[email protected]4d5901272008-11-06 00:33:50878#endif
[email protected]82d89ab2014-02-28 18:25:34879 // Crash the process to generate a dump.
Torne (Richard Coles)54b86796a62018-07-24 14:59:52880#if defined(OFFICIAL_BUILD) && defined(NDEBUG)
881 IMMEDIATE_CRASH();
882#else
[email protected]82d89ab2014-02-28 18:25:34883 base::debug::BreakDebugger();
Torne (Richard Coles)54b86796a62018-07-24 14:59:52884#endif
initial.commitd7cae122008-07-26 21:49:38885 }
886 }
887}
888
[email protected]eae9c062011-01-11 00:50:59889// writes the common header info to the stream
890void LogMessage::Init(const char* file, int line) {
891 base::StringPiece filename(file);
892 size_t last_slash_pos = filename.find_last_of("\\/");
893 if (last_slash_pos != base::StringPiece::npos)
894 filename.remove_prefix(last_slash_pos + 1);
895
Kevin Marshall9873826d2019-10-14 20:09:35896 // Stores the base name as the null-terminated suffix substring of |filename|.
897 file_basename_ = filename.data();
898
Yuta Hijikata000df18f2020-11-18 06:55:58899#if BUILDFLAG(IS_CHROMEOS_ASH)
Yuta Hijikata9b7279a2020-08-26 16:10:54900 if (g_log_format == LogFormat::LOG_FORMAT_SYSLOG) {
901 InitWithSyslogPrefix(
902 filename, line, TickCount(), log_severity_name(severity_), g_log_prefix,
903 g_log_process_id, g_log_thread_id, g_log_timestamp, g_log_tickcount);
904 } else
Yuta Hijikata000df18f2020-11-18 06:55:58905#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Yuta Hijikata9b7279a2020-08-26 16:10:54906 {
907 // TODO(darin): It might be nice if the columns were fixed width.
908 stream_ << '[';
909 if (g_log_prefix)
910 stream_ << g_log_prefix << ':';
911 if (g_log_process_id)
912 stream_ << base::GetUniqueIdForProcess() << ':';
913 if (g_log_thread_id)
914 stream_ << base::PlatformThread::CurrentId() << ':';
915 if (g_log_timestamp) {
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39916#if defined(OS_WIN)
Yuta Hijikata9b7279a2020-08-26 16:10:54917 SYSTEMTIME local_time;
918 GetLocalTime(&local_time);
919 stream_ << std::setfill('0')
920 << std::setw(2) << local_time.wMonth
921 << std::setw(2) << local_time.wDay
922 << '/'
923 << std::setw(2) << local_time.wHour
924 << std::setw(2) << local_time.wMinute
925 << std::setw(2) << local_time.wSecond
926 << '.'
927 << std::setw(3) << local_time.wMilliseconds
928 << ':';
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39929#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
Yuta Hijikata9b7279a2020-08-26 16:10:54930 timeval tv;
931 gettimeofday(&tv, nullptr);
932 time_t t = tv.tv_sec;
933 struct tm local_time;
934 localtime_r(&t, &local_time);
935 struct tm* tm_time = &local_time;
936 stream_ << std::setfill('0')
937 << std::setw(2) << 1 + tm_time->tm_mon
938 << std::setw(2) << tm_time->tm_mday
939 << '/'
940 << std::setw(2) << tm_time->tm_hour
941 << std::setw(2) << tm_time->tm_min
942 << std::setw(2) << tm_time->tm_sec
943 << '.'
944 << std::setw(6) << tv.tv_usec
945 << ':';
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39946#else
947#error Unsupported platform
djkurtz543a3be2016-11-30 14:17:34948#endif
Yuta Hijikata9b7279a2020-08-26 16:10:54949 }
950 if (g_log_tickcount)
951 stream_ << TickCount() << ':';
952 if (severity_ >= 0) {
953 stream_ << log_severity_name(severity_);
954 } else {
955 stream_ << "VERBOSE" << -severity_;
956 }
957 stream_ << ":" << filename << "(" << line << ")] ";
[email protected]eae9c062011-01-11 00:50:59958 }
pkasting9cf9b94a2014-10-01 22:18:43959 message_start_ = stream_.str().length();
[email protected]eae9c062011-01-11 00:50:59960}
961
[email protected]d8617a62009-10-09 23:52:20962#if defined(OS_WIN)
963// This has already been defined in the header, but defining it again as DWORD
964// ensures that the type used in the header is equivalent to DWORD. If not,
965// the redefinition is a compile error.
966typedef DWORD SystemErrorCode;
967#endif
968
969SystemErrorCode GetLastSystemErrorCode() {
970#if defined(OS_WIN)
971 return ::GetLastError();
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39972#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
[email protected]d8617a62009-10-09 23:52:20973 return errno;
[email protected]d8617a62009-10-09 23:52:20974#endif
975}
976
[email protected]c914d8a2014-04-23 01:11:01977BASE_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code) {
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39978#if defined(OS_WIN)
thestig75f87352014-12-03 21:42:27979 const int kErrorMessageBufferSize = 256;
980 char msgbuf[kErrorMessageBufferSize];
[email protected]c914d8a2014-04-23 01:11:01981 DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
thestig3e4787d2015-05-19 19:31:52982 DWORD len = FormatMessageA(flags, nullptr, error_code, 0, msgbuf,
Avi Drissmane3b70bf2019-01-04 19:50:22983 base::size(msgbuf), nullptr);
[email protected]c914d8a2014-04-23 01:11:01984 if (len) {
985 // Messages returned by system end with line breaks.
986 return base::CollapseWhitespaceASCII(msgbuf, true) +
Bruce Dawson19175842017-08-02 17:00:45987 base::StringPrintf(" (0x%lX)", error_code);
[email protected]c914d8a2014-04-23 01:11:01988 }
Bruce Dawson19175842017-08-02 17:00:45989 return base::StringPrintf("Error (0x%lX) while retrieving error. (0x%lX)",
[email protected]c914d8a2014-04-23 01:11:01990 GetLastError(), error_code);
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39991#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
Robert Sesekd2f495f2017-07-25 22:03:14992 return base::safe_strerror(error_code) +
993 base::StringPrintf(" (%d)", error_code);
thestig3e4787d2015-05-19 19:31:52994#endif // defined(OS_WIN)
Fabrice de Gans-Riberi306871de2018-05-16 19:38:39995}
[email protected]d8617a62009-10-09 23:52:20996
[email protected]c914d8a2014-04-23 01:11:01997
998#if defined(OS_WIN)
[email protected]d8617a62009-10-09 23:52:20999Win32ErrorLogMessage::Win32ErrorLogMessage(const char* file,
1000 int line,
1001 LogSeverity severity,
1002 SystemErrorCode err)
Hans Wennborg12aea3e2020-04-14 15:29:001003 : LogMessage(file, line, severity), err_(err) {}
[email protected]d8617a62009-10-09 23:52:201004
1005Win32ErrorLogMessage::~Win32ErrorLogMessage() {
[email protected]c914d8a2014-04-23 01:11:011006 stream() << ": " << SystemErrorCodeToString(err_);
[email protected]20909e72012-04-05 16:57:061007 // We're about to crash (CHECK). Put |err_| on the stack (by placing it in a
1008 // field) and use Alias in hopes that it makes it into crash dumps.
1009 DWORD last_error = err_;
1010 base::debug::Alias(&last_error);
[email protected]d8617a62009-10-09 23:52:201011}
Fabrice de Gans-Riberi306871de2018-05-16 19:38:391012#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
[email protected]d8617a62009-10-09 23:52:201013ErrnoLogMessage::ErrnoLogMessage(const char* file,
1014 int line,
1015 LogSeverity severity,
1016 SystemErrorCode err)
Hans Wennborg12aea3e2020-04-14 15:29:001017 : LogMessage(file, line, severity), err_(err) {}
[email protected]d8617a62009-10-09 23:52:201018
1019ErrnoLogMessage::~ErrnoLogMessage() {
[email protected]c914d8a2014-04-23 01:11:011020 stream() << ": " << SystemErrorCodeToString(err_);
Robert Sesekd2f495f2017-07-25 22:03:141021 // We're about to crash (CHECK). Put |err_| on the stack (by placing it in a
1022 // field) and use Alias in hopes that it makes it into crash dumps.
1023 int last_error = err_;
1024 base::debug::Alias(&last_error);
[email protected]d8617a62009-10-09 23:52:201025}
thestig3e4787d2015-05-19 19:31:521026#endif // defined(OS_WIN)
[email protected]d8617a62009-10-09 23:52:201027
initial.commitd7cae122008-07-26 21:49:381028void CloseLogFile() {
Fabrice de Gans-Riberi306871de2018-05-16 19:38:391029#if defined(OS_POSIX) || defined(OS_FUCHSIA)
Benoit Lize5c98a832020-07-07 16:32:011030 base::AutoLock guard(GetLoggingLock());
ananta61762fb2015-09-18 01:00:091031#endif
[email protected]17dcf752013-07-15 21:47:091032 CloseLogFileUnlocked();
initial.commitd7cae122008-07-26 21:49:381033}
1034
Yuta Hijikata000df18f2020-11-18 06:55:581035#if BUILDFLAG(IS_CHROMEOS_ASH)
Robbie McElrath8bf49842019-08-20 22:22:531036FILE* DuplicateLogFILE() {
1037 if ((g_logging_destination & LOG_TO_FILE) == 0 || !InitializeLogFileHandle())
1038 return nullptr;
1039
1040 int log_fd = fileno(g_log_file);
1041 if (log_fd == -1)
1042 return nullptr;
1043 base::ScopedFD dup_fd(dup(log_fd));
1044 if (dup_fd == -1)
1045 return nullptr;
1046 FILE* duplicate = fdopen(dup_fd.get(), "a");
1047 if (!duplicate)
1048 return nullptr;
1049 ignore_result(dup_fd.release());
1050 return duplicate;
1051}
1052#endif
1053
Yuta Hijikata9b7279a2020-08-26 16:10:541054// Used for testing. Declared in test/scoped_logging_settings.h.
1055ScopedLoggingSettings::ScopedLoggingSettings()
1056 : enable_process_id_(g_log_process_id),
1057 enable_thread_id_(g_log_thread_id),
1058 enable_timestamp_(g_log_timestamp),
1059 enable_tickcount_(g_log_tickcount),
1060 min_log_level_(GetMinLogLevel()),
1061 message_handler_(GetLogMessageHandler()) {
Yuta Hijikata000df18f2020-11-18 06:55:581062#if BUILDFLAG(IS_CHROMEOS_ASH)
Yuta Hijikata9b7279a2020-08-26 16:10:541063 log_format_ = g_log_format;
Yuta Hijikata000df18f2020-11-18 06:55:581064#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Yuta Hijikata9b7279a2020-08-26 16:10:541065}
1066
1067ScopedLoggingSettings::~ScopedLoggingSettings() {
1068 g_log_process_id = enable_process_id_;
1069 g_log_thread_id = enable_thread_id_;
1070 g_log_timestamp = enable_timestamp_;
1071 g_log_tickcount = enable_tickcount_;
1072 SetMinLogLevel(min_log_level_);
1073 SetLogMessageHandler(message_handler_);
1074
Yuta Hijikata000df18f2020-11-18 06:55:581075#if BUILDFLAG(IS_CHROMEOS_ASH)
Yuta Hijikata9b7279a2020-08-26 16:10:541076 g_log_format = log_format_;
Yuta Hijikata000df18f2020-11-18 06:55:581077#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Yuta Hijikata9b7279a2020-08-26 16:10:541078}
1079
Yuta Hijikata000df18f2020-11-18 06:55:581080#if BUILDFLAG(IS_CHROMEOS_ASH)
Yuta Hijikata9b7279a2020-08-26 16:10:541081void ScopedLoggingSettings::SetLogFormat(LogFormat log_format) const {
1082 g_log_format = log_format;
1083}
Yuta Hijikata000df18f2020-11-18 06:55:581084#endif // BUILDFLAG(IS_CHROMEOS_ASH)
Yuta Hijikata9b7279a2020-08-26 16:10:541085
[email protected]e36ddc82009-12-08 04:22:501086void RawLog(int level, const char* message) {
erikchen0c9fe712016-03-11 22:07:491087 if (level >= g_min_log_level && message) {
[email protected]e36ddc82009-12-08 04:22:501088 size_t bytes_written = 0;
1089 const size_t message_len = strlen(message);
1090 int rv;
1091 while (bytes_written < message_len) {
1092 rv = HANDLE_EINTR(
1093 write(STDERR_FILENO, message + bytes_written,
1094 message_len - bytes_written));
1095 if (rv < 0) {
1096 // Give up, nothing we can do now.
1097 break;
1098 }
1099 bytes_written += rv;
1100 }
1101
1102 if (message_len > 0 && message[message_len - 1] != '\n') {
1103 do {
1104 rv = HANDLE_EINTR(write(STDERR_FILENO, "\n", 1));
1105 if (rv < 0) {
1106 // Give up, nothing we can do now.
1107 break;
1108 }
1109 } while (rv != 1);
1110 }
1111 }
1112
Lei Zhang93dd42572020-10-23 18:45:531113 if (level == LOGGING_FATAL)
[email protected]58580352010-10-26 04:07:501114 base::debug::BreakDebugger();
[email protected]e36ddc82009-12-08 04:22:501115}
1116
[email protected]34a907732012-01-20 06:33:271117// This was defined at the beginning of this file.
1118#undef write
1119
[email protected]f01b88a2013-02-27 22:04:001120#if defined(OS_WIN)
ananta61762fb2015-09-18 01:00:091121bool IsLoggingToFileEnabled() {
1122 return g_logging_destination & LOG_TO_FILE;
1123}
1124
Jan Wilken Dörrieb630aca2019-12-04 10:59:111125std::wstring GetLogFileFullPath() {
thestig3e4787d2015-05-19 19:31:521126 if (g_log_file_name)
1127 return *g_log_file_name;
Jan Wilken Dörrieb630aca2019-12-04 10:59:111128 return std::wstring();
[email protected]f01b88a2013-02-27 22:04:001129}
1130#endif
1131
[email protected]96fd0032009-04-24 00:13:081132} // namespace logging
initial.commitd7cae122008-07-26 21:49:381133
[email protected]81411c62014-07-08 23:03:061134std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) {
Jan Wilken Dörrie4a498d8c2021-01-20 10:19:391135 return out << (wstr ? base::WStringPiece(wstr) : base::WStringPiece());
1136}
1137
1138std::ostream& std::operator<<(std::ostream& out, const std::wstring& wstr) {
1139 return out << base::WStringPiece(wstr);
1140}
1141
1142std::ostream& std::operator<<(std::ostream& out, const char16_t* str16) {
1143 // TODO(crbug.com/911896): Drop cast once base::char16 is char16_t everywhere.
1144 return out << (str16 ? base::StringPiece16(
1145 reinterpret_cast<const base::char16*>(str16))
1146 : base::StringPiece16());
1147}
1148
1149std::ostream& std::operator<<(std::ostream& out, const std::u16string& str16) {
1150 // TODO(crbug.com/911896): Drop cast once base::char16 is char16_t everywhere.
1151 return out << base::StringPiece16(
1152 reinterpret_cast<const base::char16*>(str16.data()), str16.size());
initial.commitd7cae122008-07-26 21:49:381153}