Allow --v and --log-level switches simultaneous usage.
The current implementation, in fact, doesn't support specifying both
"--v" and "--log-level" command line switches: only "--log-level" switch
will take an effect. This looks counterintuitive.
For example, browser_tests always start the browser with the
"--log-level" switch specified, so with current implementation there's
no way to enable vlogging in browser_tests using a command line.
The suggestion is, as both of the options refer to the same underlying
"min_log_level", to make the "--v" switch have a higher priority.
BUG=
Review URL: https://codereview.chromium.org/1136463009
Cr-Commit-Position: refs/heads/master@{#330218}
diff --git a/chrome/common/logging_chrome.cc b/chrome/common/logging_chrome.cc
index 7d26587..c8458ef9 100644
--- a/chrome/common/logging_chrome.cc
+++ b/chrome/common/logging_chrome.cc
@@ -333,14 +333,19 @@
command_line.HasSwitch(switches::kNoErrorDialogs))
SuppressDialogs();
- // Use a minimum log level if the command line asks for one,
- // otherwise leave it at the default level (INFO).
- if (command_line.HasSwitch(switches::kLoggingLevel)) {
- std::string log_level = command_line.GetSwitchValueASCII(
- switches::kLoggingLevel);
+ // Use a minimum log level if the command line asks for one. Ignore this
+ // switch if there's vlog level switch present too (as both of these switches
+ // refer to the same underlying log level, and the vlog level switch has
+ // already been processed inside logging::InitLogging). If there is neither
+ // log level nor vlog level specified, then just leave the default level
+ // (INFO).
+ 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 < LOG_NUM_SEVERITIES) {
+ if (base::StringToInt(log_level, &level) && level >= 0 &&
+ level < LOG_NUM_SEVERITIES) {
logging::SetMinLogLevel(level);
} else {
DLOG(WARNING) << "Bad log level: " << log_level;