.\"
.\" $Id$
.\"
-.Dd September 20, 2006
+.Dd October 5, 2006
.Dt VARNISHLOG 1
.Os
.Sh NAME
.Op Fl w Ar file
.Op Fl X Ar regex
.Op Fl x Ar tag
+.Op Ar tag Ar regex
.Sh DESCRIPTION
The
.Nm
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
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
.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 ,
#include <errno.h>
#include <fcntl.h>
#include <regex.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
{
unsigned u;
-printf("Clean\n");
for (u = 0; u < 65536; u++) {
if (ob[u] == NULL)
continue;
/*--------------------------------------------------------------------*/
+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, "-"))
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)
exit(1);
}
}
+ if (reopen) {
+ close(fd);
+ fd = open_log(w_opt, a_flag);
+ reopen = 0;
+ }
}
exit (0);
}
.\"
.\" $Id$
.\"
-.Dd September 20, 2006
+.Dd October 5, 2006
.Dt VARNISHNCSA 1
.Os
.Sh NAME
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
#include <stdio.h>
#include <errno.h>
+#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
/*--------------------------------------------------------------------*/
+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)
{
int i, c;
struct VSL_data *vd;
const char *ofn = NULL;
- FILE *of = stdout;
int append = 0;
+ FILE *of;
vd = VSL_New();
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) {
perror(ofn);
exit(1);
}
+ if (reopen && of != stdout) {
+ fclose(of);
+ of = open_log(ofn, append);
+ reopen = 0;
+ }
}
exit(0);