Created
October 16, 2019 19:17
-
-
Save ckerr/053dff338e82a22957743d1dd5ddf167 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/atom/app/atom_main_delegate.cc b/atom/app/atom_main_delegate.cc | |
index e1318eb6d..537667389 100644 | |
--- a/atom/app/atom_main_delegate.cc | |
+++ b/atom/app/atom_main_delegate.cc | |
@@ -25,6 +25,7 @@ | |
#include "base/logging.h" | |
#include "base/mac/bundle_locations.h" | |
#include "base/path_service.h" | |
+#include "base/strings/string_number_conversions.h" | |
#include "chrome/common/chrome_paths.h" | |
#include "content/public/common/content_switches.h" | |
#include "electron/buildflags/buildflags.h" | |
@@ -128,6 +129,8 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) { | |
auto* command_line = base::CommandLine::ForCurrentProcess(); | |
logging::LoggingSettings settings; | |
+ logging::LogSeverity log_severity = logging::LOG_INFO; | |
+ | |
#if defined(OS_WIN) | |
// On Windows the terminal returns immediately, so we add a new line to | |
// prevent output in the same line as the prompt. | |
@@ -146,18 +149,32 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) { | |
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | |
#endif // !defined(OS_WIN) | |
- // Only enable logging when --enable-logging is specified. | |
- auto env = base::Environment::Create(); | |
+ const auto log_file = command_line->GetSwitchValuePath(::switches::kLogFile); | |
+ const auto log_level = command_line->GetSwitchValueNative(::switches::kLoggingLevel); | |
+ const auto env = base::Environment::Create(); | |
+ | |
+ // No logging unless requested by the user | |
if (!command_line->HasSwitch(::switches::kEnableLogging) && | |
- !env->HasVar("ELECTRON_ENABLE_LOGGING")) { | |
+ !env->HasVar("ELECTRON_ENABLE_LOGGING") && | |
+ log_file.empty() && log_level.empty()) { | |
settings.logging_dest = logging::LOG_NONE; | |
- logging::SetMinLogLevel(logging::LOG_NUM_SEVERITIES); | |
+ log_severity = logging::LOG_NUM_SEVERITIES; | |
} | |
- logging::InitLogging(settings); | |
+ // If the user specified a log file, use it | |
+ if (!log_file.empty()) { | |
+ settings.logging_dest = logging::LOG_TO_FILE; | |
+ settings.log_file = log_file.value().c_str(); | |
+ } | |
- // Logging with pid and timestamp. | |
- logging::SetLogItems(true, false, true, false); | |
+ // If the user specified a log level, use it | |
+ if (!log_level.empty() && !base::StringToInt(log_level, &log_severity)) { | |
+ std::cerr << "Invalid log level: " << log_level << std::endl; | |
+ } | |
+ | |
+ logging::SetLogItems(true/*pid*/, false, true/*timestamp*/, false); | |
+ logging::SetMinLogLevel(log_severity); | |
+ logging::InitLogging(settings); | |
// Enable convient stack printing. This is enabled by default in non-official | |
// builds. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment