Index: headless/app/headless_shell.cc |
diff --git a/headless/app/headless_shell.cc b/headless/app/headless_shell.cc |
index cd05f9796cec82027c032dfc5a6fdf020d309db9..43d344c19f1af1b84ea4fadcafecf715d3a60c0d 100644 |
--- a/headless/app/headless_shell.cc |
+++ b/headless/app/headless_shell.cc |
@@ -17,6 +17,7 @@ |
#include "base/memory/ref_counted.h" |
#include "base/memory/weak_ptr.h" |
#include "base/numerics/safe_conversions.h" |
+#include "base/path_service.h" |
#include "base/strings/string_number_conversions.h" |
#include "content/public/common/content_switches.h" |
#include "headless/app/headless_shell_switches.h" |
@@ -436,13 +437,58 @@ bool ValidateCommandLine(const base::CommandLine& command_line) { |
return true; |
} |
+void InitLogging(const base::CommandLine& command_line) { |
+ if (!command_line.HasSwitch(switches::kEnableLogging)) |
+ return; |
+ |
+ logging::LoggingDestination log_mode; |
+ if (command_line.GetSwitchValueASCII(switches::kEnableLogging) == "stderr") { |
+ log_mode = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
+ } else { |
+ log_mode = logging::LOG_TO_ALL; |
+ } |
+ |
+ if (command_line.HasSwitch(switches::kLoggingLevel) && |
+ logging::GetMinLogLevel() >= 0) { |
+ std::string log_level = |
+ command_line.GetSwitchValueASCII(switches::kLoggingLevel); |
+ int level = 0; |
+ if (base::StringToInt(log_level, &level) && level >= 0 && |
+ level < logging::LOG_NUM_SEVERITIES) { |
+ logging::SetMinLogLevel(level); |
+ } else { |
+ DLOG(WARNING) << "Bad log level: " << log_level; |
+ } |
+ } |
+ |
+ const base::FilePath log_filename(FILE_PATH_LITERAL("chrome_debug.log")); |
altimin
2017/02/02 22:44:45
Let's make output file configurable. We can use va
Sami
2017/02/02 23:15:33
Done.
|
+ base::FilePath log_path; |
+ logging::LoggingSettings settings; |
+ |
+ if (PathService::Get(base::DIR_MODULE, &log_path)) { |
+ log_path = log_path.Append(log_filename); |
+ } else { |
+ log_path = log_filename; |
+ } |
+ |
+ settings.logging_dest = log_mode; |
+ settings.log_file = log_path.value().c_str(); |
+ settings.lock_log = logging::DONT_LOCK_LOG_FILE; |
+ settings.delete_old = logging::DELETE_OLD_LOG_FILE; |
+ bool success = logging::InitLogging(settings); |
+ DCHECK(success); |
+} |
+ |
int HeadlessShellMain(int argc, const char** argv) { |
RunChildProcessIfNeeded(argc, argv); |
HeadlessShell shell; |
HeadlessBrowser::Options::Builder builder(argc, argv); |
// Enable devtools if requested. |
- base::CommandLine command_line(argc, argv); |
+ base::CommandLine::Init(argc, argv); |
+ const base::CommandLine& command_line( |
+ *base::CommandLine::ForCurrentProcess()); |
+ InitLogging(command_line); |
if (!ValidateCommandLine(command_line)) |
return EXIT_FAILURE; |