r1174 - in branches/1.0: . bin/varnishlog bin/varnishncsa

des at projects.linpro.no des at projects.linpro.no
Wed Oct 18 16:27:02 CEST 2006


Author: des
Date: 2006-10-18 16:27:02 +0200 (Wed, 18 Oct 2006)
New Revision: 1174

Modified:
   branches/1.0/
   branches/1.0/bin/varnishlog/varnishlog.1
   branches/1.0/bin/varnishlog/varnishlog.c
   branches/1.0/bin/varnishncsa/varnishncsa.1
   branches/1.0/bin/varnishncsa/varnishncsa.c
Log:
 r31766 at cat (orig r1135):  des | 2006-10-05 11:50:40 +0200
 Reopen the output file on SIGHUP.  Document same.  Also document
 varnishlog's request selection feature.



Property changes on: branches/1.0
___________________________________________________________________
Name: svk:merge
   - d4fa192b-c00b-0410-8231-f00ffab90ce4:/trunk/varnish-cache:1134
   + d4fa192b-c00b-0410-8231-f00ffab90ce4:/trunk/varnish-cache:1135

Modified: branches/1.0/bin/varnishlog/varnishlog.1
===================================================================
--- branches/1.0/bin/varnishlog/varnishlog.1	2006-10-18 14:27:00 UTC (rev 1173)
+++ branches/1.0/bin/varnishlog/varnishlog.1	2006-10-18 14:27:02 UTC (rev 1174)
@@ -28,7 +28,7 @@
 .\"
 .\" $Id$
 .\"
-.Dd September 20, 2006
+.Dd October 5, 2006
 .Dt VARNISHLOG 1
 .Os
 .Sh NAME
@@ -49,6 +49,7 @@
 .Op Fl w Ar file
 .Op Fl X Ar regex
 .Op Fl x Ar tag
+.Op Ar tag Ar regex
 .Sh DESCRIPTION
 The
 .Nm
@@ -103,6 +104,9 @@
 is specified, all log entries are included.
 .It Fl o
 Group log entries by request ID.
+This has no effect when writing to a file using the
+.Fl w
+option.
 .It Fl r Ar file
 Read log entries from
 .Ar file
@@ -116,11 +120,30 @@
 The file will be overwritten unless the
 .Fl a
 option was specified.
+.Pp
+If
+.Nm
+receives a
+.Dv SIGHUP
+while writing to a file, it will reopen the file, allowing the old one
+to be rotated away.
 .It Fl X Ar regex
 Exclude log entries which match the specified regular expression.
 .It Fl x Ar tag
 Exclude log entries with the specified tag.
 .El
+.Pp
+If the
+.Fl o
+option was specified, an additional
+.Ar tag
+and
+.Ar regex
+may be specified to select only requests which generated a log entry
+with the given
+.Ar tag
+whose contents match the given
+.Ar regex .
 .Sh TAGS
 The following log entry tags are currently defined:
 .\" keep in sync with include/shmlog_tags.h
@@ -177,6 +200,18 @@
 .It Dv VCL_trace
 .It Dv WorkThread
 .El
+.Sh EXAMPLES
+The following command line simply copies all log entries to a log
+file:
+.Bd -literal -offset 4n
+$ varnishlog -w /var/log/varnish.log
+.Ed
+.Pp
+The following command line reads that same log file and displays
+requests for the front page:
+.Bd -literal -offset 4n
+$ varnishlog -r /var/log/varnish.log -c -o RxURL '^/$'
+.Ed
 .Sh SEE ALSO
 .Xr varnishd 1 ,
 .Xr varnishhist 1 ,

Modified: branches/1.0/bin/varnishlog/varnishlog.c
===================================================================
--- branches/1.0/bin/varnishlog/varnishlog.c	2006-10-18 14:27:00 UTC (rev 1173)
+++ branches/1.0/bin/varnishlog/varnishlog.c	2006-10-18 14:27:02 UTC (rev 1174)
@@ -34,6 +34,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <regex.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -80,7 +81,6 @@
 {
 	unsigned u;
 
-printf("Clean\n");
 	for (u = 0; u < 65536; u++) {
 		if (ob[u] == NULL)
 			continue;
@@ -200,12 +200,21 @@
 
 /*--------------------------------------------------------------------*/
 
+static sig_atomic_t reopen;
+
 static void
-do_write(struct VSL_data *vd, const char *w_opt, int a_flag)
+sighup(int sig)
 {
-	int fd, flags, i;
-	unsigned char *p;
 
+	(void)sig;
+	reopen = 1;
+}
+
+static int
+open_log(const char *w_opt, int a_flag)
+{
+	int fd, flags;
+
 	flags = (a_flag ? O_APPEND : O_TRUNC) | O_WRONLY | O_CREAT;
 	if (!strcmp(w_opt, "-"))
 		fd = STDOUT_FILENO;
@@ -215,6 +224,17 @@
 		perror(w_opt);
 		exit (1);
 	}
+	return (fd);
+}
+
+static void
+do_write(struct VSL_data *vd, const char *w_opt, int a_flag)
+{
+	int fd, i;
+	unsigned char *p;
+
+	fd = open_log(w_opt, a_flag);
+	signal(SIGHUP, sighup);
 	while (1) {
 		i = VSL_NextLog(vd, &p);
 		if (i < 0)
@@ -226,6 +246,11 @@
 				exit(1);
 			}
 		}
+		if (reopen) {
+			close(fd);
+			fd = open_log(w_opt, a_flag);
+			reopen = 0;
+		}
 	}
 	exit (0);
 }

Modified: branches/1.0/bin/varnishncsa/varnishncsa.1
===================================================================
--- branches/1.0/bin/varnishncsa/varnishncsa.1	2006-10-18 14:27:00 UTC (rev 1173)
+++ branches/1.0/bin/varnishncsa/varnishncsa.1	2006-10-18 14:27:02 UTC (rev 1174)
@@ -28,7 +28,7 @@
 .\"
 .\" $Id$
 .\"
-.Dd September 20, 2006
+.Dd October 5, 2006
 .Dt VARNISHNCSA 1
 .Os
 .Sh NAME
@@ -114,6 +114,13 @@
 The file will be overwritten unless the
 .Fl a
 option was specified.
+.Pp
+If
+.Nm
+receives a
+.Dv SIGHUP
+while writing to a file, it will reopen the file, allowing the old one
+to be rotated away.
 .It Fl X Ar regex
 Exclude log entries which match the specified regular expression.
 .It Fl x Ar tag

Modified: branches/1.0/bin/varnishncsa/varnishncsa.c
===================================================================
--- branches/1.0/bin/varnishncsa/varnishncsa.c	2006-10-18 14:27:00 UTC (rev 1173)
+++ branches/1.0/bin/varnishncsa/varnishncsa.c	2006-10-18 14:27:02 UTC (rev 1174)
@@ -42,6 +42,7 @@
 
 #include <stdio.h>
 #include <errno.h>
+#include <signal.h>
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -220,7 +221,31 @@
 
 /*--------------------------------------------------------------------*/
 
+static sig_atomic_t reopen;
+
 static void
+sighup(int sig)
+{
+
+	(void)sig;
+	reopen = 1;
+}
+
+static FILE *
+open_log(const char *ofn, int append)
+{
+	FILE *of;
+
+	if ((of = fopen(ofn, append ? "a" : "w")) == NULL) {
+		perror(ofn);
+		exit(1);
+	}
+	return (of);
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
 usage(void)
 {
 	fprintf(stderr, "usage: varnishncsa %s [-aV] [-w file]\n", VSL_ARGS);
@@ -233,8 +258,8 @@
 	int i, c;
 	struct VSL_data *vd;
 	const char *ofn = NULL;
-	FILE *of = stdout;
 	int append = 0;
+	FILE *of;
 
 	vd = VSL_New();
 
@@ -264,11 +289,12 @@
 	if (VSL_OpenLog(vd))
 		exit(1);
 
-	if (ofn && (of = fopen(ofn, append ? "a" : "w")) == NULL) {
-		perror(ofn);
-		exit(1);
+	if (ofn) {
+		of = open_log(ofn, append);
+		signal(SIGHUP, sighup);
 	} else {
 		ofn = "stdout";
+		of = stdout;
 	}
 
 	while (VSL_Dispatch(vd, extended_log_format, of) == 0) {
@@ -276,6 +302,11 @@
 			perror(ofn);
 			exit(1);
 		}
+		if (reopen && of != stdout) {
+			fclose(of);
+			of = open_log(ofn, append);
+			reopen = 0;
+		}
 	}
 
 	exit(0);




More information about the varnish-commit mailing list