add support for displaying log files on standard input
Change-Id: I5b4ec4a170fa79089d250dbda5ef4daaaa2ea742
diff --git a/aos/linux_code/logging/log_displayer.cc b/aos/linux_code/logging/log_displayer.cc
index bc00ddc..05a12fe 100644
--- a/aos/linux_code/logging/log_displayer.cc
+++ b/aos/linux_code/logging/log_displayer.cc
@@ -23,6 +23,7 @@
const char *kArgsHelp = "[OPTION]... [FILE]\n"
"Display log file FILE (created by BinaryLogReader) to stdout.\n"
"FILE is \"aos_log-current\" by default.\n"
+ "FILE can also be \"-\" to read from standard input.\n"
"\n"
" -n, --name NAME only display entries from processes named NAME\n"
" -l, --level LEVEL "
@@ -215,7 +216,12 @@
fprintf(stderr, "displaying down to level %s from file '%s'\n",
::aos::logging::log_str(filter_level), filename);
- int fd = open(filename, O_RDONLY);
+ int fd;
+ if (strcmp(filename, "-") == 0) {
+ fd = STDIN_FILENO;
+ } else {
+ fd = open(filename, O_RDONLY);
+ }
if (fd == -1) {
PLOG(FATAL, "couldn't open file '%s' for reading", filename);