From 42ee2e4f8fc2c7e42214c981853db3c7ebbb5128 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Fri, 31 Jan 2020 09:03:05 -0800 Subject: [PATCH] libbase: Have LogdLogger use LOGGER_ENTRY_MAX_PAYLOAD for its buffer LogdLogger has its own buffer for adding the file and line number to FATAL messages, but it is much lower than LOGGER_ENTRY_MAX_PAYLOAD and that causes problems now that more logs are piped through this logger, so increase the limit to maximum. Also, in the case that the file and line number are not added, simply pass the buffer through to liblog, since there is no reason to copy to a separate buffer. Bug: 148678509 Test: build, unit tests Change-Id: I064aa34641e784dca6c529c51cb192069821d64a --- base/logging.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/base/logging.cpp b/base/logging.cpp index a8687067a..f42b9966b 100644 --- a/base/logging.cpp +++ b/base/logging.cpp @@ -340,18 +340,18 @@ void LogdLogger::operator()(LogId id, LogSeverity severity, const char* tag, int lg_id = LogIdTolog_id_t(id); - char log_message[1024]; + char log_message_with_file[4068]; // LOGGER_ENTRY_MAX_PAYLOAD, not available in the NDK. if (priority == ANDROID_LOG_FATAL && file != nullptr) { - snprintf(log_message, sizeof(log_message), "%s:%u] %s", file, line, message); - } else { - snprintf(log_message, sizeof(log_message), "%s", message); + snprintf(log_message_with_file, sizeof(log_message_with_file), "%s:%u] %s", file, line, + message); + message = log_message_with_file; } static auto& liblog_functions = GetLibLogFunctions(); if (liblog_functions) { __android_logger_data logger_data = {sizeof(__android_logger_data), lg_id, priority, tag, static_cast(nullptr), 0}; - liblog_functions->__android_log_logd_logger(&logger_data, log_message); + liblog_functions->__android_log_logd_logger(&logger_data, message); } else { __android_log_buf_print(lg_id, priority, tag, "%s", message); }