From: des Date: Thu, 5 Oct 2006 09:50:40 +0000 (+0000) Subject: Reopen the output file on SIGHUP. Document same. Also document X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b4ac5b27111496e631b4537beb1c808576fb4e4;p=varnish Reopen the output file on SIGHUP. Document same. Also document varnishlog's request selection feature. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1135 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishlog/varnishlog.1 b/varnish-cache/bin/varnishlog/varnishlog.1 index abec09a2..ce11f564 100644 --- a/varnish-cache/bin/varnishlog/varnishlog.1 +++ b/varnish-cache/bin/varnishlog/varnishlog.1 @@ -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 , diff --git a/varnish-cache/bin/varnishlog/varnishlog.c b/varnish-cache/bin/varnishlog/varnishlog.c index b9775f5a..ab51b9df 100644 --- a/varnish-cache/bin/varnishlog/varnishlog.c +++ b/varnish-cache/bin/varnishlog/varnishlog.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -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); } diff --git a/varnish-cache/bin/varnishncsa/varnishncsa.1 b/varnish-cache/bin/varnishncsa/varnishncsa.1 index 42445460..bf0e91ef 100644 --- a/varnish-cache/bin/varnishncsa/varnishncsa.1 +++ b/varnish-cache/bin/varnishncsa/varnishncsa.1 @@ -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 diff --git a/varnish-cache/bin/varnishncsa/varnishncsa.c b/varnish-cache/bin/varnishncsa/varnishncsa.c index c57b38ed..480eacda 100644 --- a/varnish-cache/bin/varnishncsa/varnishncsa.c +++ b/varnish-cache/bin/varnishncsa/varnishncsa.c @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -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);