From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jeremy Rose <jeremya@chromium.org>
Date: Mon, 2 Aug 2021 15:56:56 -0700
Subject: only create a console if logging to stderr

This fixes an issue on Windows where, when `--enable-logging=file` is
passed and the app was not run from the console, a console window would
be created for each child process, despite logs being redirected to a
file.

diff --git a/content/app/content_main.cc b/content/app/content_main.cc
index 332b7d026e0365a66d5f4f275a90b48d0f2db5aa..3813fe1a3b2e95af5e213201ab3ea08a656e01c3 100644
--- a/content/app/content_main.cc
+++ b/content/app/content_main.cc
@@ -381,8 +381,12 @@ RunContentProcess(ContentMainParams params,
 
 #if BUILDFLAG(IS_WIN)
     // Route stdio to parent console (if any) or create one.
-    if (base::CommandLine::ForCurrentProcess()->HasSwitch(
-            switches::kEnableLogging)) {
+    auto* cmd_line = base::CommandLine::ForCurrentProcess();
+    bool log_to_stderr =
+        cmd_line->HasSwitch(switches::kEnableLogging) &&
+        cmd_line->GetSwitchValueASCII(switches::kEnableLogging) != "file" &&
+        !cmd_line->HasSwitch(switches::kLogFile);
+    if (log_to_stderr) {
       base::RouteStdioToConsole(true);
     }
 #endif
