]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Read the log file from stdin for --convert and --split
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 21 Aug 2012 14:01:49 +0000 (16:01 +0200)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 21 Aug 2012 14:01:49 +0000 (16:01 +0200)
The two command line arguments can read the input log file from the
standard input.

convlog.c
sarg.1
sarg_manpage.xml
splitlog.c

index 5bd70a90ce41d59bed90897ecb9f4b2a1df8e1a0..6a1f47e306dee23838a3a79f2f3178388e45fbfa 100644 (file)
--- 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 5606ec85a3bc0951920a98fc6994150b271f35a9..7dd6ce3dde062c5f13b90252d4bba39e34d6e2b1 100644 (file)
--- a/sarg.1
+++ b/sarg.1
@@ -1,7 +1,7 @@
 '\" t
 .\"     Title: sarg
 .\"    Author: Frédéric Marchal <fmarchal@users.sourceforge.net>
-.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
+.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
 .\"      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
index 87bc8adc24ca76fc407b2cd0a7d30a511a96b6b5..5283f0cd920a012e732ede70cef44e99d19c4abf 100644 (file)
@@ -121,6 +121,10 @@ Read <replaceable>filename</replaceable> for a list of the web hosts to exclude
 Convert a <application>squid</application> 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.
 </para>
+<para>
+If the input log file name is <replaceable>-</replaceable>, the input log file
+is read from standard input.
+</para>
 </listitem>
 </varlistentry>
 
@@ -311,8 +315,12 @@ If it is combined with <option>--convert</option>
 the dates are also converted to a human-readable format.
 </para>
 <para>
-Combined with <option>-P</option>, the log is written in several files each containing one day of the
-original log.
+If the input log file name is <replaceable>-</replaceable>, the input log file
+is read from standard input.
+</para>
+<para>
+Combined with <option>-P</option>, the log is written in several files each
+containing one day worth of the original log.
 </para>
 </listitem>
 </varlistentry>
index 82e5a2a015cf6a56378e6404b6db9d6bce2aad28..ab557c8c7072559ba3991c136504918d344d0637 100644 (file)
@@ -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) {