From: Frédéric Marchal Date: Tue, 21 Aug 2012 14:01:49 +0000 (+0200) Subject: Read the log file from stdin for --convert and --split X-Git-Tag: v2.3.3~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c16ffe7164c926c95c3b262fa54be100b8f7683;p=thirdparty%2Fsarg.git Read the log file from stdin for --convert and --split The two command line arguments can read the input log file from the standard input. --- diff --git a/convlog.c b/convlog.c index 5bd70a9..6a1f47e 100644 --- a/convlog.c +++ b/convlog.c @@ -42,7 +42,9 @@ void convlog(const char *arq, char *df, int dfrom, int duntil) if(arq[0] == '\0') arq="/var/log/squid/access.log"; - if((fp_in=MY_FOPEN(arq,"r"))==NULL) { + if (arq[0]=='-' && arq[1]=='\0') { + fp_in=stdin; + } else if((fp_in=MY_FOPEN(arq,"r"))==NULL) { debuga(_("(convlog) Cannot open log file %s - %s\n"),arq,strerror(errno)); exit(EXIT_FAILURE); } @@ -76,7 +78,7 @@ void convlog(const char *arq, char *df, int dfrom, int duntil) } longline_destroy(&line); - if (fclose(fp_in)==EOF) { + if (fp_in!=stdin && fclose(fp_in)==EOF) { debuga(_("Failed to close file %s - %s\n"),arq,strerror(errno)); } } diff --git a/sarg.1 b/sarg.1 index 5606ec8..7dd6ce3 100644 --- a/sarg.1 +++ b/sarg.1 @@ -1,7 +1,7 @@ '\" t .\" Title: sarg .\" Author: Frédéric Marchal -.\" Generator: DocBook XSL Stylesheets v1.76.1 +.\" Generator: DocBook XSL Stylesheets v1.75.2 .\" Date: 27 May 2012 .\" Manual: SARG .\" Source: sarg @@ -101,6 +101,9 @@ the section called \(lqHOST EXCLUSION FILE\(rq\&. Convert a squid log file date/time field to a human\-readable format\&. All the log files are read and output as one text on the standard output\&. +.sp +If the input log file name is +\fI\-\fR, the input log file is read from standard input\&. .RE .PP \fB\-\-css\fR @@ -278,8 +281,11 @@ parameter\&. If it is combined with \fB\-\-convert\fR the dates are also converted to a human\-readable format\&. .sp +If the input log file name is +\fI\-\fR, the input log file is read from standard input\&. +.sp Combined with -\fB\-P\fR, the log is written in several files each containing one day of the original log\&. +\fB\-P\fR, the log is written in several files each containing one day worth of the original log\&. .RE .PP \fB\-t \fR\fB\fIstring\fR\fR diff --git a/sarg_manpage.xml b/sarg_manpage.xml index 87bc8ad..5283f0c 100644 --- a/sarg_manpage.xml +++ b/sarg_manpage.xml @@ -121,6 +121,10 @@ Read filename for a list of the web hosts to exclude Convert a squid log file date/time field to a human-readable format. All the log files are read and output as one text on the standard output. + +If the input log file name is -, the input log file +is read from standard input. + @@ -311,8 +315,12 @@ If it is combined with the dates are also converted to a human-readable format. -Combined with , the log is written in several files each containing one day of the -original log. +If the input log file name is -, the input log file +is read from standard input. + + +Combined with , the log is written in several files each +containing one day worth of the original log. diff --git a/splitlog.c b/splitlog.c index 82e5a2a..ab557c8 100644 --- a/splitlog.c +++ b/splitlog.c @@ -78,7 +78,9 @@ void splitlog(const char *arq, const char *df, int dfrom, int duntil, int conver if(arq[0] == '\0') arq="/var/log/squid/access.log"; - if((fp_in=MY_FOPEN(arq,"r"))==NULL) { + if (arq[0]=='-' && arq[1]=='\0') { + fp_in=stdin; + } else if((fp_in=MY_FOPEN(arq,"r"))==NULL) { debuga(_("(splitlog) Cannot open log file %s - %s\n"),arq,strerror(errno)); exit(EXIT_FAILURE); } @@ -139,7 +141,7 @@ void splitlog(const char *arq, const char *df, int dfrom, int duntil, int conver } longline_destroy(&line); - if (fclose(fp_in)==EOF) { + if (fp_in!=stdin && fclose(fp_in)==EOF) { debuga(_("Failed to close file %s - %s\n"),arq,strerror(errno)); } if (autosplit && fp_ou) {