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

Commit 97ea74a4 authored by Jeremy Wu's avatar Jeremy Wu
Browse files

Floss: reroute libchrome logs to syslog

Currently, libchrome logs are discarded entirely. In this CL, we hijack
the messages and send them to syslog before they are gone.

Note that `TraceConf` needs to be set in `bt_stack.conf` before this
takes effect.

Bug: 279873537
Tag: #floss
Test: Build and verify
Change-Id: I9189946aed140dc185d8a8965609e57b31f1b1d8
parent 7efc8cbf
Loading
Loading
Loading
Loading
+51 −1
Original line number Diff line number Diff line
@@ -17,8 +17,50 @@
 ******************************************************************************/
#include <base/command_line.h>
#include <base/logging.h>
#include <base/strings/stringprintf.h>
#include <osi/include/log.h>

#include "main_int.h"

#ifdef TARGET_FLOSS
#include <syslog.h>
static bool MessageHandler(int severity, const char* file, int line,
                           size_t message_start, const std::string& message) {
  ASSERT(message_start <= message.size());

  const auto str = base::StringPrintf("%s:%d - %s", file, line,
                                      message.substr(message_start).c_str());

  switch (severity) {
    case logging::LOGGING_INFO:
      severity = LOG_INFO;
      break;

    case logging::LOGGING_WARNING:
      severity = LOG_WARNING;
      break;

    case logging::LOGGING_ERROR:
      severity = LOG_ERR;
      break;

    case logging::LOGGING_FATAL:
      severity = LOG_CRIT;
      break;

    default:
      severity = LOG_DEBUG;
      break;
  }

  syslog(severity, str.c_str());

  if (severity == LOG_CRIT) abort();

  return true;
}
#endif

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
@@ -47,10 +89,18 @@ void init_cpp_logging(config_t* config) {
  base::CommandLine::Init(argc, argv);

  logging::LoggingSettings log_settings;

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

  // Android already logs thread_id, proc_id, timestamp, so disable those.
  logging::SetLogItems(false, false, false, false);

#ifdef TARGET_FLOSS
  log_settings.logging_dest =
      logging::LOG_TO_SYSTEM_DEBUG_LOG | logging::LOG_TO_STDERR;

  logging::SetLogMessageHandler(MessageHandler);
#endif
}
+1 −1
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ static std::unique_ptr<config_t> config;
static future_t* init() {
// TODO(armansito): Find a better way than searching by a hardcoded path.
#if defined(TARGET_FLOSS)
  const char* path = "/var/lib/bluetooth/bt_stack.conf";
  const char* path = "/etc/bluetooth/bt_stack.conf";
#elif defined(__ANDROID__)
  const char* path = "/apex/com.android.btservices/etc/bluetooth/bt_stack.conf";
#else   // !defined(__ANDROID__)