blob: f7c10fed4fa4fdbdfb0a5ec54e9be816275f59ae [file] [log] [blame]
Jakub Pawlowski75b83662016-09-27 18:24:59 -07001/******************************************************************************
2 *
Jakub Pawlowski5b790fe2017-09-18 09:00:20 -07003 * Copyright 2016 Android Open Source Project
Jakub Pawlowski75b83662016-09-27 18:24:59 -07004 *
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 Pawlowski75b83662016-09-27 18:24:59 -070018#include <base/command_line.h>
19#include "main_int.h"
20
Myles Watson911d1ae2016-11-28 16:44:40 -080021void init_cpp_logging(config_t* config) {
Jakub Pawlowski75b83662016-09-27 18:24:59 -070022 // 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 Pawlowskif3fb3162017-10-06 00:04:27 -070027 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 Pawlowski75b83662016-09-27 18:24:59 -070031
32 int argc = 1;
Myles Watson911d1ae2016-11-28 16:44:40 -080033 const char* argv[] = {"bt_stack", NULL, NULL};
Jakub Pawlowski75b83662016-09-27 18:24:59 -070034
35 if (loggingV != NULL) {
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -070036 argv[argc] = loggingV->c_str();
Jakub Pawlowski75b83662016-09-27 18:24:59 -070037 argc++;
38 }
39
40 if (loggingVModule != NULL) {
Jakub Pawlowskif3fb3162017-10-06 00:04:27 -070041 argv[argc] = loggingVModule->c_str();
Jakub Pawlowski75b83662016-09-27 18:24:59 -070042 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 Hef2af1c42016-12-13 01:59:12 -080055}