Files
cromite/build/patches/WIN-Fix-log-to-file.patch
2026-02-01 15:18:16 +01:00

110 lines
4.2 KiB
Diff

From: uazo <uazo@users.noreply.github.com>
Date: Fri, 14 Apr 2023 13:55:58 +0000
Subject: WIN Fix log to file
Allows log activation without opening the console window.
Log rotation enabled by default.
---
chrome/common/logging_chrome.cc | 11 ++++++++---
chrome/common/logging_chrome.h | 6 +++++-
content/app/content_main.cc | 9 ++++++---
3 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/chrome/common/logging_chrome.cc b/chrome/common/logging_chrome.cc
--- a/chrome/common/logging_chrome.cc
+++ b/chrome/common/logging_chrome.cc
@@ -37,7 +37,7 @@
#include "chrome/common/logging_chrome.h"
#include "content/public/common/content_switches.h"
-#if BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN)
#include "ash/constants/ash_switches.h"
#include "base/i18n/time_formatting.h"
#include "third_party/icu/source/i18n/unicode/timezone.h"
@@ -212,7 +212,7 @@ LoggingDestination DetermineLoggingDestination(
return LoggingDestFromCommandLine(command_line, unused);
}
-#if BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN)
bool RotateLogFile(const base::FilePath& target_path) {
DCHECK(!target_path.empty());
// If the old log file doesn't exist, do nothing.
@@ -257,7 +257,9 @@ bool RotateLogFile(const base::FilePath& target_path) {
return true;
}
+#endif // BUILDFLAG(IS_WIN)
+#if BUILDFLAG(IS_CHROMEOS)
base::FilePath SetUpSymlinkIfNeeded(const base::FilePath& symlink_path,
bool new_log) {
DCHECK(!symlink_path.empty());
@@ -430,6 +432,9 @@ void InitChromeLogging(const base::CommandLine& command_line,
// since that will remove the newly created link instead.
delete_old_log_file = APPEND_TO_OLD_LOG_FILE;
#endif // BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_WIN)
+ RotateLogFile(log_path);
+#endif
}
} else {
log_locking_state = DONT_LOCK_LOG_FILE;
@@ -594,7 +599,7 @@ bool DialogsAreSuppressed() {
return dialogs_are_suppressed_;
}
-#if BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN)
base::FilePath GenerateTimestampedName(const base::FilePath& base_path,
base::Time timestamp) {
return base_path.InsertBeforeExtensionASCII(
diff --git a/chrome/common/logging_chrome.h b/chrome/common/logging_chrome.h
--- a/chrome/common/logging_chrome.h
+++ b/chrome/common/logging_chrome.h
@@ -34,10 +34,14 @@ LoggingDestination DetermineLoggingDestination(
// write new logs to the latest log file. Otherwise, we reuse the existing file
// if exists.
base::FilePath SetUpLogFile(const base::FilePath& target_path, bool new_log);
+#endif // BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN)
// Allow external calls to the internal method for testing.
bool RotateLogFile(const base::FilePath& target_path);
+#endif
+#if BUILDFLAG(IS_CHROMEOS)
#if defined(UNIT_TEST)
// Expose the following methods only for tests.
@@ -67,7 +71,7 @@ base::FilePath GetLogFileName(const base::CommandLine& command_line);
// otherwise.
bool DialogsAreSuppressed();
-#if BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN)
// Inserts timestamp before file extension (if any) in the form
// "_yymmdd-hhmmss".
base::FilePath GenerateTimestampedName(const base::FilePath& base_path,
diff --git a/content/app/content_main.cc b/content/app/content_main.cc
--- a/content/app/content_main.cc
+++ b/content/app/content_main.cc
@@ -344,9 +344,12 @@ NO_STACK_PROTECTOR int RunContentProcess(
} else if (command_line->HasSwitch(switches::kEnableLogging)) {
// Route stdio to parent console (if any) or create one, do not create a
// console in children if handles are being passed.
- bool create_console = command_line->GetSwitchValueASCII(
- switches::kEnableLogging) != "handle";
- base::RouteStdioToConsole(create_console);
+ std::string logging_destination =
+ command_line->GetSwitchValueASCII(switches::kEnableLogging);
+ bool create_console = logging_destination != "handle";
+ if (logging_destination == "stderr") {
+ base::RouteStdioToConsole(create_console);
+ }
}
#endif
--