• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2014 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #include "shill/logging.h"
18 
19 #include <string>
20 
21 #include <base/command_line.h>
22 #include <base/strings/string_number_conversions.h>
23 
24 using base::CommandLine;
25 using std::string;
26 
27 namespace shill {
28 
29 namespace switches {
30 
31 const char kLogLevel[] = "log-level";
32 const char kLogScopes[] = "log-scopes";
33 
34 }  // namespace switches
35 
SetLogLevelFromCommandLine(CommandLine * cl)36 void SetLogLevelFromCommandLine(CommandLine* cl) {
37   if (cl->HasSwitch(switches::kLogLevel)) {
38     string log_level = cl->GetSwitchValueASCII(switches::kLogLevel);
39     int level = 0;
40     if (base::StringToInt(log_level, &level) &&
41         level < logging::LOG_NUM_SEVERITIES) {
42       logging::SetMinLogLevel(level);
43       // Like VLOG, SLOG uses negative verbose level.
44       shill::ScopeLogger::GetInstance()->set_verbose_level(-level);
45     } else {
46       LOG(WARNING) << "Bad log level: " << log_level;
47     }
48   }
49 
50   if (cl->HasSwitch(switches::kLogScopes)) {
51     string log_scopes = cl->GetSwitchValueASCII(switches::kLogScopes);
52     shill::ScopeLogger::GetInstance()->EnableScopesByName(log_scopes);
53   }
54 }
55 
56 }  // namespace shill
57 
58 
59