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

Commit 4a265f58 authored by Henri Chataing's avatar Henri Chataing Committed by Gerrit Code Review
Browse files

Merge "libbluetooth_log: Always output the source file and line" into main

parents 58d60d2b 62a6d144
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -33,8 +33,13 @@ void vlog(Level level, char const* tag, char const* file_name, int line,
  }

  // Format to stack buffer.
  // liblog uses a different default depending on the execution context
  // (host or device); the file and line are not systematically included.
  // In order to have consistent logs we include it manually in the log
  // message.
  truncating_buffer<kBufferSize> buffer;
  fmt::format_to(std::back_insert_iterator(buffer), "{}: ", function_name);
  fmt::format_to(std::back_insert_iterator(buffer), "{}:{} {}: ", file_name,
                 line, function_name);
  fmt::vformat_to(std::back_insert_iterator(buffer), fmt, vargs);

  // Send message to liblog.
@@ -43,8 +48,8 @@ void vlog(Level level, char const* tag, char const* file_name, int line,
      .buffer_id = LOG_ID_MAIN,
      .priority = static_cast<android_LogPriority>(level),
      .tag = tag,
      .file = file_name,
      .line = static_cast<uint32_t>(line),
      .file = nullptr,
      .line = 0,
      .message = buffer.c_str(),
  };
  __android_log_write_log_message(&message);
+34 −23
Original line number Diff line number Diff line
@@ -51,10 +51,11 @@ TEST(BluetoothLoggerTest, verbose) {
  ASSERT_TRUE(androidLogMessage.has_value());
  EXPECT_EQ(androidLogMessage->priority, ANDROID_LOG_VERBOSE);
  EXPECT_STREQ(androidLogMessage->tag, LOG_TAG);
  EXPECT_STREQ(androidLogMessage->file,
               "packages/modules/Bluetooth/system/log/src/vlog_test.cc");
  EXPECT_EQ(androidLogMessage->line, 49);
  EXPECT_STREQ(androidLogMessage->message, "TestBody: verbose test");
  EXPECT_EQ(androidLogMessage->file, nullptr);
  EXPECT_EQ(androidLogMessage->line, 0);
  EXPECT_STREQ(androidLogMessage->message,
               "packages/modules/Bluetooth/system/log/src/vlog_test.cc:49 "
               "TestBody: verbose test");
}

TEST(BluetoothLoggerTest, debug) {
@@ -65,10 +66,11 @@ TEST(BluetoothLoggerTest, debug) {
  ASSERT_TRUE(androidLogMessage.has_value());
  EXPECT_EQ(androidLogMessage->priority, ANDROID_LOG_DEBUG);
  EXPECT_STREQ(androidLogMessage->tag, LOG_TAG);
  EXPECT_STREQ(androidLogMessage->file,
               "packages/modules/Bluetooth/system/log/src/vlog_test.cc");
  EXPECT_EQ(androidLogMessage->line, 63);
  EXPECT_STREQ(androidLogMessage->message, "TestBody: debug test");
  EXPECT_STREQ(androidLogMessage->file, nullptr);
  EXPECT_EQ(androidLogMessage->line, 0);
  EXPECT_STREQ(androidLogMessage->message,
               "packages/modules/Bluetooth/system/log/src/vlog_test.cc:64 "
               "TestBody: debug test");
}

TEST(BluetoothLoggerTest, info) {
@@ -79,10 +81,11 @@ TEST(BluetoothLoggerTest, info) {
  ASSERT_TRUE(androidLogMessage.has_value());
  EXPECT_EQ(androidLogMessage->priority, ANDROID_LOG_INFO);
  EXPECT_STREQ(androidLogMessage->tag, LOG_TAG);
  EXPECT_STREQ(androidLogMessage->file,
               "packages/modules/Bluetooth/system/log/src/vlog_test.cc");
  EXPECT_EQ(androidLogMessage->line, 77);
  EXPECT_STREQ(androidLogMessage->message, "TestBody: info test");
  EXPECT_STREQ(androidLogMessage->file, nullptr);
  EXPECT_EQ(androidLogMessage->line, 0);
  EXPECT_STREQ(androidLogMessage->message,
               "packages/modules/Bluetooth/system/log/src/vlog_test.cc:79 "
               "TestBody: info test");
}

TEST(BluetoothLoggerTest, warn) {
@@ -93,10 +96,11 @@ TEST(BluetoothLoggerTest, warn) {
  ASSERT_TRUE(androidLogMessage.has_value());
  EXPECT_EQ(androidLogMessage->priority, ANDROID_LOG_WARN);
  EXPECT_STREQ(androidLogMessage->tag, LOG_TAG);
  EXPECT_STREQ(androidLogMessage->file,
               "packages/modules/Bluetooth/system/log/src/vlog_test.cc");
  EXPECT_EQ(androidLogMessage->line, 91);
  EXPECT_STREQ(androidLogMessage->message, "TestBody: warn test");
  EXPECT_STREQ(androidLogMessage->file, nullptr);
  EXPECT_EQ(androidLogMessage->line, 0);
  EXPECT_STREQ(androidLogMessage->message,
               "packages/modules/Bluetooth/system/log/src/vlog_test.cc:94 "
               "TestBody: warn test");
}

TEST(BluetoothLoggerTest, error) {
@@ -107,10 +111,11 @@ TEST(BluetoothLoggerTest, error) {
  ASSERT_TRUE(androidLogMessage.has_value());
  EXPECT_EQ(androidLogMessage->priority, ANDROID_LOG_ERROR);
  EXPECT_STREQ(androidLogMessage->tag, LOG_TAG);
  EXPECT_STREQ(androidLogMessage->file,
               "packages/modules/Bluetooth/system/log/src/vlog_test.cc");
  EXPECT_EQ(androidLogMessage->line, 105);
  EXPECT_STREQ(androidLogMessage->message, "TestBody: error test");
  EXPECT_STREQ(androidLogMessage->file, nullptr);
  EXPECT_EQ(androidLogMessage->line, 0);
  EXPECT_STREQ(androidLogMessage->message,
               "packages/modules/Bluetooth/system/log/src/vlog_test.cc:109 "
               "TestBody: error test");
}

TEST(BluetoothLoggerTest, null_string_parameter) {
@@ -118,17 +123,23 @@ TEST(BluetoothLoggerTest, null_string_parameter) {

  char const* const_null_str = nullptr;
  log::info("input: {}", const_null_str);
  EXPECT_STREQ(androidLogMessage->message, "TestBody: input: (nullptr)");
  EXPECT_STREQ(androidLogMessage->message,
               "packages/modules/Bluetooth/system/log/src/vlog_test.cc:125 "
               "TestBody: input: (nullptr)");

  androidLogMessage.reset();

  char* null_str = nullptr;
  log::info("input: {}", null_str);
  EXPECT_STREQ(androidLogMessage->message, "TestBody: input: (nullptr)");
  EXPECT_STREQ(androidLogMessage->message,
               "packages/modules/Bluetooth/system/log/src/vlog_test.cc:133 "
               "TestBody: input: (nullptr)");

  androidLogMessage.reset();

  char const* nonnull_str = "hello world";
  log::info("input: {}", nonnull_str);
  EXPECT_STREQ(androidLogMessage->message, "TestBody: input: hello world");
  EXPECT_STREQ(androidLogMessage->message,
               "packages/modules/Bluetooth/system/log/src/vlog_test.cc:141 "
               "TestBody: input: hello world");
}