From df42ce4cf33faf800e6cef6d203bd9448a436dbd Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 30 Mar 2016 12:38:29 -0700 Subject: [PATCH] logcat: support --regex on binary buffers as-is (cherry pick from commit aa730c1145a4670dead4973b791d47258a1c29f9) - Do not restrict regex on LOG_ID_EVENTS or LOG_ID_SECURITY. - some logcat_panic messages need to incorporate a newline. - deal with some coding standards issues. Bug: 27706081 Change-Id: Ie647fd62d027b01004177559d68b8e5a346705e6 --- logcat/logcat.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp index bbb01143f..0fe4c4ca0 100644 --- a/logcat/logcat.cpp +++ b/logcat/logcat.cpp @@ -83,6 +83,7 @@ static pcrecpp::RE* g_regex; static size_t g_maxCount; static size_t g_printCount; +// if showHelp is set, newline required in fmt statement to transition to usage __noreturn static void logcat_panic(bool showHelp, const char *fmt, ...) __printflike(2,3); static int openLogFile (const char *pathname) @@ -149,16 +150,12 @@ void printBinary(struct log_msg *buf) TEMP_FAILURE_RETRY(write(g_outFD, buf, size)); } -static bool regexOk(const AndroidLogEntry& entry, log_id_t id) +static bool regexOk(const AndroidLogEntry& entry) { - if (! g_regex) { + if (!g_regex) { return true; } - if (id == LOG_ID_EVENTS || id == LOG_ID_SECURITY) { - return false; - } - std::string messageString(entry.message, entry.messageLen); return g_regex->PartialMatch(messageString); @@ -193,7 +190,7 @@ static void processBuffer(log_device_t* dev, struct log_msg *buf) } if (android_log_shouldPrintLine(g_logformat, entry.tag, entry.priority) && - regexOk(entry, buf->id())) { + regexOk(entry)) { bytesWritten = android_log_printLogLine(g_logformat, g_outFD, &entry); g_printCount++; @@ -966,7 +963,7 @@ int main(int argc, char **argv) } if (g_maxCount && got_t) { - logcat_panic(true, "Cannot use -m (--max-count) and -t together"); + logcat_panic(true, "Cannot use -m (--max-count) and -t together\n"); } if (!devices) { @@ -1185,7 +1182,7 @@ int main(int argc, char **argv) dev = NULL; log_device_t unexpected("unexpected", false); - while (!g_maxCount || g_printCount < g_maxCount) { + while (!g_maxCount || (g_printCount < g_maxCount)) { struct log_msg log_msg; log_device_t* d; int ret = android_logger_list_read(logger_list, &log_msg);