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

Commit b64958d1 authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi
Browse files

Refactor logging init flags

Rather than limiting debug log control to just debug or not, replace the
init flags with INIT_default_log_level and INIT_log_level_for_tag which
allows finer grained control of which log levels to enable.

This commit also disables some tags by default on Floss which are overly
verbose and limits the debug log level unless a verbose flag is
provided.

Bug: 274672964
Tag: #floss
Test: Load on ChromeOS and observe generated logs.

Change-Id: Iace11364ea28daf85663edae1dd21bfd16e073a8
parent 8d3c22a8
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@

#include "bt_target.h"  // Must be first to define build configuration

#define LOG_TAG "bt_bta_av"

#include "bta/av/bta_av_int.h"
#include "osi/include/log.h"

+1 −1
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ void load_levels_from_config(const config_t* config) {
    if (value != -1) {
      functions->trace_level = value;
    }
    if (bluetooth::common::InitFlags::IsDebugLoggingEnabledForAll()) {
    if (bluetooth::common::InitFlags::GetDefaultLogLevel() >= LOG_TAG_VERBOSE) {
      LOG_INFO("Enable logging for %s because all debug logs are enabled",
               functions->trc_name);
      functions->trace_level = BT_TRACE_LEVEL_VERBOSE;
+2 −2
Original line number Diff line number Diff line
@@ -33,12 +33,12 @@ table InitFlagsData {
    gd_remote_name_request_is_enabled:bool (privacy:"Any");
    gd_rust_is_enabled:bool (privacy:"Any");
    gd_security_is_enabled:bool (privacy:"Any");
    get_default_log_level:int (privacy:"Any");
    get_hci_adapter:int (privacy:"Any");
    // get_log_level_for_tag -- skipped in dumpsys
    hfp_dynamic_version_is_enabled:bool (privacy:"Any");
    irk_rotation_is_enabled:bool (privacy:"Any");
    // is_debug_logging_enabled_for_tag -- skipped in dumpsys
    leaudio_targeted_announcement_reconnection_mode_is_enabled: bool (privacy:"Any");
    logging_debug_enabled_for_all_is_enabled:bool (privacy:"Any");
    pass_phy_update_callback_is_enabled:bool (privacy:"Any");
    pbap_pse_dynamic_version_upgrade_is_enabled:bool (privacy:"Any");
    periodic_advertising_adi_is_enabled:bool (privacy:"Any");
+4 −4
Original line number Diff line number Diff line
@@ -36,12 +36,12 @@ class InitFlags final {
    init_flags::load(std::move(rusted_flags));
  }

  inline static bool IsDebugLoggingEnabledForTag(const std::string& tag) {
    return init_flags::is_debug_logging_enabled_for_tag(tag);
  inline static int GetLogLevelForTag(const std::string& tag) {
    return init_flags::get_log_level_for_tag(tag);
  }

  inline static bool IsDebugLoggingEnabledForAll() {
    return init_flags::logging_debug_enabled_for_all_is_enabled();
  inline static int GetDefaultLogLevel() {
    return init_flags::get_default_log_level();
  }

  inline static bool IsDeviceIotConfigLoggingEnabled() {
+31 −25
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@

#include <gtest/gtest.h>

#include "os/log_tags.h"

using bluetooth::common::InitFlags;

TEST(InitFlagsTest, test_enable_btm_flush_discovery_queue_on_search_cancel) {
@@ -35,44 +37,48 @@ TEST(InitFlagsTest, test_leaudio_targeted_announcement_reconnection_mode) {
}

TEST(InitFlagsTest, test_enable_debug_logging_for_all) {
  const char* input[] = {"INIT_logging_debug_enabled_for_all=true", nullptr};
  const char* input[] = {"INIT_default_log_level=5", nullptr};
  InitFlags::Load(input);
  ASSERT_TRUE(InitFlags::IsDebugLoggingEnabledForTag("foo"));
  ASSERT_TRUE(InitFlags::IsDebugLoggingEnabledForTag("bar"));
  ASSERT_TRUE(InitFlags::IsDebugLoggingEnabledForAll());
  ASSERT_EQ(InitFlags::GetLogLevelForTag("foo"), LOG_TAG_DEBUG);
  ASSERT_EQ(InitFlags::GetLogLevelForTag("bar"), LOG_TAG_DEBUG);
  ASSERT_EQ(InitFlags::GetDefaultLogLevel(), LOG_TAG_DEBUG);
}

TEST(InitFlagsTest, test_enable_debug_logging_for_tags) {
  const char* input[] = {"INIT_logging_debug_enabled_for_tags=foo,bar,hello", nullptr};
  InitFlags::Load(input);
  ASSERT_TRUE(InitFlags::IsDebugLoggingEnabledForTag("foo"));
  ASSERT_TRUE(InitFlags::IsDebugLoggingEnabledForTag("bar"));
  ASSERT_TRUE(InitFlags::IsDebugLoggingEnabledForTag("hello"));
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("Foo"));
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForAll());
  ASSERT_EQ(InitFlags::GetLogLevelForTag("foo"), LOG_TAG_VERBOSE);
  ASSERT_EQ(InitFlags::GetLogLevelForTag("bar"), LOG_TAG_VERBOSE);
  ASSERT_EQ(InitFlags::GetLogLevelForTag("hello"), LOG_TAG_VERBOSE);
  ASSERT_EQ(InitFlags::GetLogLevelForTag("Foo"), LOG_TAG_INFO);
  ASSERT_EQ(InitFlags::GetDefaultLogLevel(), LOG_TAG_INFO);
}

TEST(InitFlagsTest, test_disable_debug_logging_for_tags) {
  const char* input[] = {"INIT_logging_debug_disabled_for_tags=foo,bar,hello", nullptr};
  const char* input[] = {
      "INIT_logging_debug_disabled_for_tags=foo,bar,hello",
      "INIT_default_log_level_str=LOG_DEBUG",
      nullptr};
  InitFlags::Load(input);
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("foo"));
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("bar"));
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("hello"));
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("Foo"));
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForAll());
  ASSERT_EQ(InitFlags::GetLogLevelForTag("foo"), LOG_TAG_INFO);
  ASSERT_EQ(InitFlags::GetLogLevelForTag("bar"), LOG_TAG_INFO);
  ASSERT_EQ(InitFlags::GetLogLevelForTag("hello"), LOG_TAG_INFO);
  ASSERT_EQ(InitFlags::GetLogLevelForTag("Foo"), LOG_TAG_DEBUG);
  ASSERT_EQ(InitFlags::GetDefaultLogLevel(), LOG_TAG_DEBUG);
}

TEST(InitFlagsTest, test_debug_logging_multiple_flags) {
  const char* input[] = {"INIT_logging_debug_enabled_for_tags=foo,hello",
  const char* input[] = {
      "INIT_logging_debug_enabled_for_tags=foo,hello",
      "INIT_logging_debug_disabled_for_tags=foo,bar",
                         "INIT_logging_debug_enabled_for_all=false",
      "INIT_default_log_level_str=LOG_WARN",
      nullptr};
  InitFlags::Load(input);
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("foo"));
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("bar"));
  ASSERT_TRUE(InitFlags::IsDebugLoggingEnabledForTag("hello"));
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForTag("Foo"));
  ASSERT_FALSE(InitFlags::IsDebugLoggingEnabledForAll());
  ASSERT_EQ(InitFlags::GetLogLevelForTag("foo"), LOG_TAG_INFO);
  ASSERT_EQ(InitFlags::GetLogLevelForTag("bar"), LOG_TAG_INFO);
  ASSERT_EQ(InitFlags::GetLogLevelForTag("hello"), LOG_TAG_VERBOSE);
  ASSERT_EQ(InitFlags::GetLogLevelForTag("Foo"), LOG_TAG_WARN);
  ASSERT_EQ(InitFlags::GetDefaultLogLevel(), LOG_TAG_WARN);
}

TEST(InitFlagsTest, test_enable_snoop_logger_socket) {
Loading