Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0eefffee authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Enable libbase logging for whole stack

Currently, only C++ code in the service/ folder can use libbase logging.
This patch makes sure that logging can be used and is properly
configured for usage when the stack is running as part of Bluetooth.apk.

Bug: 31806042
Change-Id: I1f8be79ba9999b53ece0b5217a893b4bd20ecafc
parent 88e5f2ba
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -40,6 +40,12 @@ TRC_GAP=2
TRC_BNEP=2
TRC_PAN=2

# This is Log configuration for new C++ code using LOG() macros.
# See libchrome/base/logging.h for description on how to configure your logs.
# sample configuration:
#LoggingV=--v=0
#LoggingVModule=--vmodule=*/btm/*=1,btm_ble_multi*=2,btif_*=1

# PTS testing helpers

# Secure connections only mode.
+18 −1
Original line number Diff line number Diff line
@@ -4,11 +4,28 @@ LOCAL_PATH:= $(call my-dir)
# ========================================================
include $(CLEAR_VARS)

LOCAL_CPP_EXTENSION := .cc

#
# Workaround for libchrome and -DNDEBUG usage.
#
# Test whether the original TARGET_GLOBAL_CFLAGS contains -DNDEBUG.
# This is needed as a workaround to make sure that
# libchrome and local files calling logging::InitLogging()
# are consistent with the usage of -DNDEBUG .
# ========================================================
ifneq (,$(findstring NDEBUG,$(TARGET_GLOBAL_CFLAGS)))
  btmain_orig_TARGET_NDEBUG := -DBT_LIBCHROME_NDEBUG
else
  btmain_orig_TARGET_NDEBUG :=
endif

# platform specific
LOCAL_SRC_FILES := \
	bte_main.c \
	bte_init.c \
	bte_logmsg.c \
	bte_init_cpp_logging.cc \
	bte_conf.c \
	stack_config.c

@@ -101,7 +118,7 @@ LOCAL_REQUIRED_MODULES := \
    libbt-hci \
    libbt-vendor

LOCAL_CFLAGS += $(bluetooth_CFLAGS) -DBUILDCFG
LOCAL_CFLAGS += $(bluetooth_CFLAGS) -DBUILDCFG $(btmain_orig_TARGET_NDEBUG)
LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)

+60 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2016 Android Open Source Project
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

#ifdef BT_LIBCHROME_NDEBUG
#define NDEBUG 1
#endif

#include <base/command_line.h>
#include "main_int.h"

void init_cpp_logging(config_t *config) {
  // Command line and log level might be also configured in service/main.cpp
  // when running the bluetoothtbd daemon. If it's already configured, skip
  // configuring.
  if (base::CommandLine::InitializedForCurrentProcess()) return;

  const char *loggingV =
      config_get_string(config, CONFIG_DEFAULT_SECTION, "LoggingV", NULL);
  const char *loggingVModule =
      config_get_string(config, CONFIG_DEFAULT_SECTION, "LoggingVModule", NULL);

  int argc = 1;
  const char *argv[] = {"bt_stack", NULL, NULL};

  if (loggingV != NULL) {
    argv[argc] = loggingV;
    argc++;
  }

  if (loggingVModule != NULL) {
    argv[argc] = loggingVModule;
    argc++;
  }

  // Init command line object with logging switches
  base::CommandLine::Init(argc, argv);

  logging::LoggingSettings log_settings;
  if (!logging::InitLogging(log_settings)) {
    LOG(ERROR) << "Failed to set up logging";
  }

  // Android already logs thread_id, proc_id, timestamp, so disable those.
  logging::SetLogItems(false, false, false, false);
}
 No newline at end of file
+4 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
#include "port_api.h"
#include "sdp_api.h"
#include "stack_config.h"
#include "main_int.h"

#if (AVDT_INCLUDED == TRUE)
#include "avdt_api.h"
@@ -231,12 +232,15 @@ static void load_levels_from_config(const config_t *config) {
}

static future_t *init(void) {

  const stack_config_t *stack_config = stack_config_get_interface();
  if (!stack_config->get_trace_config_enabled()) {
    LOG_INFO(LOG_TAG, "using compile default trace settings");
    return NULL;
  }

  init_cpp_logging(stack_config->get_all());

  load_levels_from_config(stack_config->get_all());
  return NULL;
}

system/main/main_int.h

0 → 100644
+35 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2016 Android Open Source Project
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

#ifndef MAIN_INT_H
#define MAIN_INT_H

#include "osi/include/config.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Initiates the logging for C++ */
void init_cpp_logging(config_t *config);

#ifdef __cplusplus
}
#endif

#endif // MAIN_INT_H
 No newline at end of file