1 /******************************************************************************
2 *
3 * Copyright 2016 Android Open Source Project
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 ******************************************************************************/
18 #include <base/command_line.h>
19 #include "main_int.h"
20
init_cpp_logging(config_t * config)21 void init_cpp_logging(config_t* config) {
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
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);
31
32 int argc = 1;
33 const char* argv[] = {"bt_stack", NULL, NULL};
34
35 if (loggingV != NULL) {
36 argv[argc] = loggingV->c_str();
37 argc++;
38 }
39
40 if (loggingVModule != NULL) {
41 argv[argc] = loggingVModule->c_str();
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);
55 }
56