diff options
author | Mark Salyzyn <salyzyn@google.com> | 2015-02-25 23:34:47 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-02-25 23:34:47 +0000 |
commit | da26197873c97515d1e59137b8347667689ced42 (patch) | |
tree | 84b647d7b5c4c3fc526f294037fe05d329426108 | |
parent | a2fc0f86a1618fe9605a085c34ec7f088f0872f5 (diff) | |
parent | 7b30ff8d8768241af0e036e4d9296d07b2dde66a (diff) | |
download | system_core-da26197873c97515d1e59137b8347667689ced42.zip system_core-da26197873c97515d1e59137b8347667689ced42.tar.gz system_core-da26197873c97515d1e59137b8347667689ced42.tar.bz2 |
Merge "logcat: Add -D print dividers flag"
-rw-r--r-- | logcat/logcat.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp index 829a0af..d831d66 100644 --- a/logcat/logcat.cpp +++ b/logcat/logcat.cpp @@ -1,4 +1,4 @@ -// Copyright 2006-2014 The Android Open Source Project +// Copyright 2006-2015 The Android Open Source Project #include <assert.h> #include <ctype.h> @@ -178,18 +178,19 @@ error: return; } -static void maybePrintStart(log_device_t* dev) { - if (!dev->printed) { - dev->printed = true; +static void maybePrintStart(log_device_t* dev, bool printDividers) { + if (!dev->printed || printDividers) { if (g_devCount > 1 && !g_printBinary) { char buf[1024]; - snprintf(buf, sizeof(buf), "--------- beginning of %s\n", + snprintf(buf, sizeof(buf), "--------- %s %s\n", + dev->printed ? "switch to" : "beginning of", dev->device); if (write(g_outFD, buf, strlen(buf)) < 0) { perror("output error"); exit(-1); } } + dev->printed = true; } } @@ -227,6 +228,7 @@ static void show_help(const char *cmd) " -n <count> Sets max number of rotated logs to <count>, default 4\n" " -v <format> Sets the log print format, where <format> is:\n\n" " brief color long process raw tag thread threadtime time\n\n" + " -D print dividers between each log buffer\n" " -c clear (flush) the entire log and exit\n" " -d dump the log and then exit (don't block)\n" " -t <count> print only the most recent <count> lines (implies -d)\n" @@ -329,6 +331,7 @@ int main(int argc, char **argv) log_device_t* devices = NULL; log_device_t* dev; bool needBinary = false; + bool printDividers = false; struct logger_list *logger_list; unsigned int tail_lines = 0; log_time tail_time(log_time::EPOCH); @@ -345,7 +348,7 @@ int main(int argc, char **argv) for (;;) { int ret; - ret = getopt(argc, argv, "cdt:T:gG:sQf:r:n:v:b:BSpP:"); + ret = getopt(argc, argv, "cdDt:T:gG:sQf:r:n:v:b:BSpP:"); if (ret < 0) { break; @@ -398,6 +401,10 @@ int main(int argc, char **argv) } break; + case 'D': + printDividers = true; + break; + case 'g': getLogSize = 1; break; @@ -839,8 +846,10 @@ int main(int argc, char **argv) if (needBinary) android::g_eventTagMap = android_openEventTagMap(EVENT_TAG_MAP_FILE); + dev = NULL; while (1) { struct log_msg log_msg; + log_device_t* d; int ret = android_logger_list_read(logger_list, &log_msg); if (ret == 0) { @@ -865,17 +874,20 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } - for(dev = devices; dev; dev = dev->next) { - if (android_name_to_log_id(dev->device) == log_msg.id()) { + for(d = devices; d; d = d->next) { + if (android_name_to_log_id(d->device) == log_msg.id()) { break; } } - if (!dev) { + if (!d) { fprintf(stderr, "read: Unexpected log ID!\n"); exit(EXIT_FAILURE); } - android::maybePrintStart(dev); + if (dev != d) { + dev = d; + android::maybePrintStart(dev, printDividers); + } if (android::g_printBinary) { android::printBinary(&log_msg); } else { |