Commit 42aa25b9 authored by John Chen's avatar John Chen Committed by Commit Bot

[ChromeDriver] Add --log-level command line switch

Add a new command line switch for ChromeDriver, to allow more
flexibility in controlling the log level.

Bug: chromedriver:2221
Change-Id: I788c56d823d7d63b9f65ce31105230d2ffa47887
Reviewed-on: https://chromium-review.googlesource.com/912589
Commit-Queue: John Chen <johnchen@chromium.org>
Reviewed-by: default avatarJonathon Kereliuk <kereliuk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#539539}
parent 2dbfc509
...@@ -377,7 +377,9 @@ Status LaunchDesktopChrome(URLRequestContextGetter* context_getter, ...@@ -377,7 +377,9 @@ Status LaunchDesktopChrome(URLRequestContextGetter* context_getter,
#if defined(OS_POSIX) #if defined(OS_POSIX)
base::ScopedFD devnull; base::ScopedFD devnull;
if (!base::CommandLine::ForCurrentProcess()->HasSwitch("verbose")) { const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
if (!cmd_line->HasSwitch("verbose") &&
cmd_line->GetSwitchValueASCII("log-level") != "ALL") {
// Redirect stderr to /dev/null, so that Chrome log spew doesn't confuse // Redirect stderr to /dev/null, so that Chrome log spew doesn't confuse
// users. // users.
devnull.reset(HANDLE_EINTR(open("/dev/null", O_WRONLY))); devnull.reset(HANDLE_EINTR(open("/dev/null", O_WRONLY)));
......
...@@ -253,11 +253,32 @@ bool InitLogging() { ...@@ -253,11 +253,32 @@ bool InitLogging() {
return false; return false;
} }
} }
if (cmd_line->HasSwitch("silent"))
int num_level_switches = 0;
if (cmd_line->HasSwitch("silent")) {
g_log_level = Log::kOff; g_log_level = Log::kOff;
num_level_switches++;
}
if (cmd_line->HasSwitch("verbose")) if (cmd_line->HasSwitch("verbose")) {
g_log_level = Log::kAll; g_log_level = Log::kAll;
num_level_switches++;
}
if (cmd_line->HasSwitch("log-level")) {
if (!WebDriverLog::NameToLevel(cmd_line->GetSwitchValueASCII("log-level"),
&g_log_level)) {
printf("Invalid --log-level value.\n");
return false;
}
num_level_switches++;
}
if (num_level_switches > 1) {
printf("Only one of --log-level, --verbose, or --silent is allowed.\n");
return false;
}
// Turn on VLOG for chromedriver. This is parsed during logging::InitLogging. // Turn on VLOG for chromedriver. This is parsed during logging::InitLogging.
cmd_line->AppendSwitchASCII("vmodule", "*/chrome/test/chromedriver/*=3"); cmd_line->AppendSwitchASCII("vmodule", "*/chrome/test/chromedriver/*=3");
......
...@@ -256,9 +256,11 @@ int main(int argc, char *argv[]) { ...@@ -256,9 +256,11 @@ int main(int argc, char *argv[]) {
"adb-port=PORT", "adb server port", "adb-port=PORT", "adb server port",
"log-path=FILE", "write server log to file instead of stderr, " "log-path=FILE", "write server log to file instead of stderr, "
"increases log level to INFO", "increases log level to INFO",
"verbose", "log verbosely", "log-level=LEVEL", "set log level: ALL, DEBUG, INFO, WARNING, "
"SEVERE, OFF",
"verbose", "log verbosely (equivalent to --log-level=ALL)",
"silent", "log nothing (equivalent to --log-level=OFF)",
"version", "print the version number and exit", "version", "print the version number and exit",
"silent", "log nothing",
"url-base", "base URL path prefix for commands, e.g. wd/url", "url-base", "base URL path prefix for commands, e.g. wd/url",
"port-server", "address of server to contact for reserving a port", "port-server", "address of server to contact for reserving a port",
"whitelisted-ips", "comma-separated whitelist of remote IPv4 addresses " "whitelisted-ips", "comma-separated whitelist of remote IPv4 addresses "
...@@ -321,7 +323,8 @@ int main(int argc, char *argv[]) { ...@@ -321,7 +323,8 @@ int main(int argc, char *argv[]) {
whitelisted_ips = base::SplitString( whitelisted_ips = base::SplitString(
whitelist, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); whitelist, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
} }
if (!cmd_line->HasSwitch("silent")) { if (!cmd_line->HasSwitch("silent") &&
cmd_line->GetSwitchValueASCII("log-level") != "OFF") {
printf("Starting ChromeDriver %s on port %u\n", kChromeDriverVersion, port); printf("Starting ChromeDriver %s on port %u\n", kChromeDriverVersion, port);
if (!allow_remote) { if (!allow_remote) {
printf("Only local connections are allowed.\n"); printf("Only local connections are allowed.\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment