From 5f1be92e8de0d058d9fb25e2851db7cf10425a8d Mon Sep 17 00:00:00 2001 From: Andreas Ericsson Date: Fri, 12 Mar 2010 23:58:43 +0100 Subject: [PATCH] showlog: Implement --skip and --limit They do more or less what's expected of them. --skip lets one skip X rows that should have been printed. --limit makes the app print a maximum of --limit lines. 386 hardware imposes a limit of 4.2 billion lines for these two variables, but I suppose we can live with that. Signed-off-by: Andreas Ericsson --- showlog.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/showlog.c b/showlog.c index d8a2bbd..896c6fe 100644 --- a/showlog.c +++ b/showlog.c @@ -16,6 +16,7 @@ static time_t ltime; /* the timestamp from the current log-line */ static uint severity; static const char *image_url = "/ninja/application/views/themes/default/icons/16x16"; static int reverse_parse_files; +static uint skip, limit; #define EVT_PROCESS (1 << 0) #define EVT_NOTIFY (1 << 1) @@ -289,8 +290,20 @@ static void print_line(int type, char *line, uint len) { struct tm t; + /* are we still skipping? If so, return early */ + if (skip) { + skip--; + return; + } + pre_print_mangle_line(&t, line, len); real_print_line(type, &t, line, len); + + /* if we've printed all the lines we should, just exit */ + if (limit) { + if (!--limit) + exit(0); + } } @@ -531,6 +544,8 @@ static void usage(const char *fmt, ...) printf(" --hide-notifications hide notification messages\n"); printf(" --hide-logrotation hide log rotation messages\n"); printf(" --hide-initial hide INITIAL and CURRENT states\n"); + printf(" --skip= number of filtered in messages to skip\n"); + printf(" --limit= max number of messages to print\n"); printf(" --host= show log entries for the named host\n"); printf(" --service= show log entries for the named service\n"); printf(" --first= first log-entry to show\n"); @@ -652,6 +667,14 @@ int main(int argc, char **argv) } /* options parsed below require arguments */ + if (!strcmp(arg, "--skip")) { + skip = strtoul(opt, NULL, 0); + continue; + } + if (!strcmp(arg, "--limit")) { + limit = strtoul(opt, NULL, 0); + continue; + } if (!strcmp(arg, "--host")) { event_filter |= EVT_HOST; add_interesting_object(opt); -- 2.11.4.GIT