From c9202777cf0a135be729b1bfdb4c8c57344296e6 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 30 Mar 2016 09:38:31 -0700 Subject: [PATCH] logcat: add --print flag To be used in combination with --regex and --max-count flags to allow all prints to pass through, but still stop when max-count is hit. Bug: 27706081 Change-Id: Idaa9f0b44586a885b9d9f367824b0072c0853227 --- logcat/logcat.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp index bb6304128..b7980d924 100644 --- a/logcat/logcat.cpp +++ b/logcat/logcat.cpp @@ -82,6 +82,7 @@ static pcrecpp::RE* g_regex; // 0 means "infinite" static size_t g_maxCount; static size_t g_printCount; +static bool g_printItAnyways; // 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); @@ -189,14 +190,16 @@ static void processBuffer(log_device_t* dev, struct log_msg *buf) goto error; } - if (android_log_shouldPrintLine(g_logformat, entry.tag, entry.priority) && - regexOk(entry)) { - bytesWritten = android_log_printLogLine(g_logformat, g_outFD, &entry); + if (android_log_shouldPrintLine(g_logformat, entry.tag, entry.priority)) { + bool match = regexOk(entry); - g_printCount++; + g_printCount += match; + if (match || g_printItAnyways) { + bytesWritten = android_log_printLogLine(g_logformat, g_outFD, &entry); - if (bytesWritten < 0) { - logcat_panic(false, "output error"); + if (bytesWritten < 0) { + logcat_panic(false, "output error"); + } } } @@ -296,6 +299,8 @@ static void show_help(const char *cmd) " --regex where is a regular expression\n" " -m quit after printing lines. This is meant to be\n" " --max-count= paired with --regex, but will work on its own.\n" + " --print paired with --regex and --max-count to let content bypass\n" + " regex filter but still stop at number of matches.\n" " -t print only the most recent lines (implies -d)\n" " -t '