summaryrefslogtreecommitdiffstats
path: root/chromium/base/logging.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-01-20 13:40:20 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-01-22 12:41:23 +0000
commit7961cea6d1041e3e454dae6a1da660b453efd238 (patch)
treec0eeb4a9ff9ba32986289c1653d9608e53ccb444 /chromium/base/logging.cc
parentb7034d0803538058e5c9d904ef03cf5eab34f6ef (diff)
BASELINE: Update Chromium to 78.0.3904.130
Change-Id: If185e0c0061b3437531c97c9c8c78f239352a68b Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/base/logging.cc')
-rw-r--r--chromium/base/logging.cc135
1 files changed, 80 insertions, 55 deletions
diff --git a/chromium/base/logging.cc b/chromium/base/logging.cc
index 4c4bfa6af52..04aabb67465 100644
--- a/chromium/base/logging.cc
+++ b/chromium/base/logging.cc
@@ -10,6 +10,7 @@
#include "base/pending_task.h"
#include "base/stl_util.h"
#include "base/task/common/task_annotator.h"
+#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#if defined(OS_WIN)
@@ -74,7 +75,7 @@ typedef HANDLE MutexHandle;
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
-#include <unistd.h>
+#include "base/process/process_handle.h"
#define MAX_PATH PATH_MAX
typedef FILE* FileHandle;
typedef pthread_mutex_t* MutexHandle;
@@ -118,6 +119,10 @@ typedef pthread_mutex_t* MutexHandle;
#include "base/posix/safe_strerror.h"
#endif
+#if defined(OS_CHROMEOS)
+#include "base/files/scoped_file.h"
+#endif
+
namespace logging {
namespace {
@@ -174,21 +179,6 @@ base::stack<LogAssertHandlerFunction>& GetLogAssertHandlerStack() {
// A log message handler that gets notified of every log message we process.
LogMessageHandlerFunction log_message_handler = nullptr;
-// Helper functions to wrap platform differences.
-
-int32_t CurrentProcessId() {
-#if defined(OS_WIN)
- return GetCurrentProcessId();
-#elif defined(OS_FUCHSIA)
- zx_info_handle_basic_t basic = {};
- zx_object_get_info(zx_process_self(), ZX_INFO_HANDLE_BASIC, &basic,
- sizeof(basic), nullptr, nullptr);
- return basic.koid;
-#elif defined(OS_POSIX)
- return getpid();
-#endif
-}
-
uint64_t TickCount() {
#if defined(OS_WIN)
return GetTickCount();
@@ -327,52 +317,52 @@ bool InitializeLogFileHandle() {
g_log_file_name = new PathString(GetDefaultLogFile());
}
- if ((g_logging_destination & LOG_TO_FILE) != 0) {
+ if ((g_logging_destination & LOG_TO_FILE) == 0)
+ return true;
+
#if defined(OS_WIN)
- // The FILE_APPEND_DATA access mask ensures that the file is atomically
- // appended to across accesses from multiple threads.
- // https://msdn.microsoft.com/en-us/library/windows/desktop/aa364399(v=vs.85).aspx
- // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx
+ // The FILE_APPEND_DATA access mask ensures that the file is atomically
+ // appended to across accesses from multiple threads.
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/aa364399(v=vs.85).aspx
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx
+ g_log_file = CreateFile(base::as_wcstr(*g_log_file_name), FILE_APPEND_DATA,
+ FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
+ OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
+ if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) {
+ // We are intentionally not using FilePath or FileUtil here to reduce the
+ // dependencies of the logging implementation. For e.g. FilePath and
+ // FileUtil depend on shell32 and user32.dll. This is not acceptable for
+ // some consumers of base logging like chrome_elf, etc.
+ // Please don't change the code below to use FilePath.
+ // try the current directory
+ base::char16 system_buffer[MAX_PATH];
+ system_buffer[0] = 0;
+ DWORD len = ::GetCurrentDirectory(base::size(system_buffer),
+ base::as_writable_wcstr(system_buffer));
+ if (len == 0 || len > base::size(system_buffer))
+ return false;
+
+ *g_log_file_name = system_buffer;
+ // Append a trailing backslash if needed.
+ if (g_log_file_name->back() != L'\\')
+ *g_log_file_name += STRING16_LITERAL("\\");
+ *g_log_file_name += STRING16_LITERAL("debug.log");
+
g_log_file = CreateFile(base::as_wcstr(*g_log_file_name), FILE_APPEND_DATA,
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) {
- // We are intentionally not using FilePath or FileUtil here to reduce the
- // dependencies of the logging implementation. For e.g. FilePath and
- // FileUtil depend on shell32 and user32.dll. This is not acceptable for
- // some consumers of base logging like chrome_elf, etc.
- // Please don't change the code below to use FilePath.
- // try the current directory
- base::char16 system_buffer[MAX_PATH];
- system_buffer[0] = 0;
- DWORD len = ::GetCurrentDirectory(base::size(system_buffer),
- base::as_writable_wcstr(system_buffer));
- if (len == 0 || len > base::size(system_buffer))
- return false;
-
- *g_log_file_name = system_buffer;
- // Append a trailing backslash if needed.
- if (g_log_file_name->back() != L'\\')
- *g_log_file_name += STRING16_LITERAL("\\");
- *g_log_file_name += STRING16_LITERAL("debug.log");
-
- g_log_file =
- CreateFile(base::as_wcstr(*g_log_file_name), FILE_APPEND_DATA,
- FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL, nullptr);
- if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) {
- g_log_file = nullptr;
- return false;
- }
+ g_log_file = nullptr;
+ return false;
}
+ }
#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
- g_log_file = fopen(g_log_file_name->c_str(), "a");
- if (g_log_file == nullptr)
- return false;
+ g_log_file = fopen(g_log_file_name->c_str(), "a");
+ if (g_log_file == nullptr)
+ return false;
#else
#error Unsupported platform
#endif
- }
return true;
}
@@ -393,6 +383,11 @@ void CloseLogFileUnlocked() {
CloseFile(g_log_file);
g_log_file = nullptr;
+
+ // If we initialized logging via an externally-provided file descriptor, we
+ // won't have a log path set and shouldn't try to reopen the log file.
+ if (!g_log_file_name)
+ g_logging_destination &= ~LOG_TO_FILE;
}
} // namespace
@@ -415,6 +410,7 @@ bool BaseInitLoggingImpl(const LoggingSettings& settings) {
CHECK_EQ(settings.logging_dest & ~(LOG_TO_SYSTEM_DEBUG_LOG | LOG_TO_STDERR),
0u);
#endif
+
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
// Don't bother initializing |g_vlog_info| unless we use one of the
// vlog switches.
@@ -453,7 +449,7 @@ bool BaseInitLoggingImpl(const LoggingSettings& settings) {
return true;
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
- LoggingLock::Init(settings.lock_log, settings.log_file);
+ LoggingLock::Init(settings.lock_log, settings.log_file_path);
LoggingLock logging_lock;
#endif
@@ -461,9 +457,17 @@ bool BaseInitLoggingImpl(const LoggingSettings& settings) {
// default log file will re-initialize to the new options.
CloseLogFileUnlocked();
+#if defined(OS_CHROMEOS)
+ if (settings.log_file) {
+ DCHECK(!settings.log_file_path);
+ g_log_file = settings.log_file;
+ return true;
+ }
+#endif
+
if (!g_log_file_name)
g_log_file_name = new PathString();
- *g_log_file_name = settings.log_file;
+ *g_log_file_name = settings.log_file_path;
if (settings.delete_old == DELETE_OLD_LOG_FILE)
DeleteFilePath(*g_log_file_name);
@@ -640,6 +644,8 @@ LogMessage::~LogMessage() {
#endif
stream_ << std::endl;
std::string str_newline(stream_.str());
+ TRACE_LOG_MESSAGE(
+ file_, base::StringPiece(str_newline).substr(message_start_), line_);
// Give any log message handler first dibs on the message.
if (log_message_handler &&
@@ -962,7 +968,7 @@ void LogMessage::Init(const char* file, int line) {
if (g_log_prefix)
stream_ << g_log_prefix << ':';
if (g_log_process_id)
- stream_ << CurrentProcessId() << ':';
+ stream_ << base::GetUniqueIdForProcess() << ':';
if (g_log_thread_id)
stream_ << base::PlatformThread::CurrentId() << ':';
if (g_log_timestamp) {
@@ -1090,6 +1096,25 @@ void CloseLogFile() {
CloseLogFileUnlocked();
}
+#if defined(OS_CHROMEOS)
+FILE* DuplicateLogFILE() {
+ if ((g_logging_destination & LOG_TO_FILE) == 0 || !InitializeLogFileHandle())
+ return nullptr;
+
+ int log_fd = fileno(g_log_file);
+ if (log_fd == -1)
+ return nullptr;
+ base::ScopedFD dup_fd(dup(log_fd));
+ if (dup_fd == -1)
+ return nullptr;
+ FILE* duplicate = fdopen(dup_fd.get(), "a");
+ if (!duplicate)
+ return nullptr;
+ ignore_result(dup_fd.release());
+ return duplicate;
+}
+#endif
+
void RawLog(int level, const char* message) {
if (level >= g_min_log_level && message) {
size_t bytes_written = 0;