Jakub Pawlowski | 75b8366 | 2016-09-27 18:24:59 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Jakub Pawlowski | 5b790fe | 2017-09-18 09:00:20 -0700 | [diff] [blame] | 3 | * Copyright 2016 Android Open Source Project |
Jakub Pawlowski | 75b8366 | 2016-09-27 18:24:59 -0700 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
Jakub Pawlowski | 75b8366 | 2016-09-27 18:24:59 -0700 | [diff] [blame] | 18 | #include <base/command_line.h> |
| 19 | #include "main_int.h" |
| 20 | |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 21 | void init_cpp_logging(config_t* config) { |
Jakub Pawlowski | 75b8366 | 2016-09-27 18:24:59 -0700 | [diff] [blame] | 22 | // Command line and log level might be also configured in service/main.cpp |
| 23 | // when running the bluetoothtbd daemon. If it's already configured, skip |
| 24 | // configuring. |
| 25 | if (base::CommandLine::InitializedForCurrentProcess()) return; |
| 26 | |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 27 | const std::string* loggingV = |
| 28 | config_get_string(*config, CONFIG_DEFAULT_SECTION, "LoggingV", NULL); |
| 29 | const std::string* loggingVModule = config_get_string( |
| 30 | *config, CONFIG_DEFAULT_SECTION, "LoggingVModule", NULL); |
Jakub Pawlowski | 75b8366 | 2016-09-27 18:24:59 -0700 | [diff] [blame] | 31 | |
| 32 | int argc = 1; |
Myles Watson | 911d1ae | 2016-11-28 16:44:40 -0800 | [diff] [blame] | 33 | const char* argv[] = {"bt_stack", NULL, NULL}; |
Jakub Pawlowski | 75b8366 | 2016-09-27 18:24:59 -0700 | [diff] [blame] | 34 | |
| 35 | if (loggingV != NULL) { |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 36 | argv[argc] = loggingV->c_str(); |
Jakub Pawlowski | 75b8366 | 2016-09-27 18:24:59 -0700 | [diff] [blame] | 37 | argc++; |
| 38 | } |
| 39 | |
| 40 | if (loggingVModule != NULL) { |
Jakub Pawlowski | f3fb316 | 2017-10-06 00:04:27 -0700 | [diff] [blame] | 41 | argv[argc] = loggingVModule->c_str(); |
Jakub Pawlowski | 75b8366 | 2016-09-27 18:24:59 -0700 | [diff] [blame] | 42 | argc++; |
| 43 | } |
| 44 | |
| 45 | // Init command line object with logging switches |
| 46 | base::CommandLine::Init(argc, argv); |
| 47 | |
| 48 | logging::LoggingSettings log_settings; |
| 49 | if (!logging::InitLogging(log_settings)) { |
| 50 | LOG(ERROR) << "Failed to set up logging"; |
| 51 | } |
| 52 | |
| 53 | // Android already logs thread_id, proc_id, timestamp, so disable those. |
| 54 | logging::SetLogItems(false, false, false, false); |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 55 | } |