Commit 961bd9f0 authored by Dag Erling Smørgrav's avatar Dag Erling Smørgrav

Reopen the output file on SIGHUP. Document same. Also document

varnishlog's request selection feature.

git-svn-id: http://www.varnish-cache.org/svn/trunk@1135 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 4a799d12
......@@ -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 @@ nor
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 @@ instead of displaying them.
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 @@ The following log entry tags are currently defined:
.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 ,
......
......@@ -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 @@ clean_order(void)
{
unsigned u;
printf("Clean\n");
for (u = 0; u < 65536; u++) {
if (ob[u] == NULL)
continue;
......@@ -200,11 +200,20 @@ do_order(struct VSL_data *vd, int argc, char **argv)
/*--------------------------------------------------------------------*/
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, "-"))
......@@ -215,6 +224,17 @@ do_write(struct VSL_data *vd, const char *w_opt, int a_flag)
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 @@ do_write(struct VSL_data *vd, const char *w_opt, int a_flag)
exit(1);
}
}
if (reopen) {
close(fd);
fd = open_log(w_opt, a_flag);
reopen = 0;
}
}
exit (0);
}
......
......@@ -28,7 +28,7 @@
.\"
.\" $Id$
.\"
.Dd September 20, 2006
.Dd October 5, 2006
.Dt VARNISHNCSA 1
.Os
.Sh NAME
......@@ -114,6 +114,13 @@ instead of displaying them.
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
......
......@@ -42,6 +42,7 @@
#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
......@@ -220,6 +221,30 @@ extended_log_format(void *priv, unsigned tag, unsigned fd, unsigned len, unsigne
/*--------------------------------------------------------------------*/
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)
{
......@@ -233,8 +258,8 @@ main(int argc, char **argv)
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 @@ main(int argc, char **argv)
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 @@ main(int argc, char **argv)
perror(ofn);
exit(1);
}
if (reopen && of != stdout) {
fclose(of);
of = open_log(ofn, append);
reopen = 0;
}
}
exit(0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment