r2575 - in trunk/varnish-cache: bin/varnishlog include lib/libvarnishapi
des at projects.linpro.no
des at projects.linpro.no
Sun Mar 9 16:14:04 CET 2008
Author: des
Date: 2008-03-09 16:14:04 +0100 (Sun, 09 Mar 2008)
New Revision: 2575
Modified:
trunk/varnish-cache/bin/varnishlog/varnishlog.1
trunk/varnish-cache/include/varnishapi.h
trunk/varnish-cache/lib/libvarnishapi/shmlog.c
Log:
Add -k option which specifies the number of log entries to keep. Along with
-s, this allows varnishlog to be used to extract part of a log file, or
partition a log file into smaller sections.
Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.1
===================================================================
--- trunk/varnish-cache/bin/varnishlog/varnishlog.1 2008-03-08 16:59:38 UTC (rev 2574)
+++ trunk/varnish-cache/bin/varnishlog/varnishlog.1 2008-03-09 15:14:04 UTC (rev 2575)
@@ -28,7 +28,7 @@
.\"
.\" $Id$
.\"
-.Dd March 8, 2008
+.Dd March 9, 2008
.Dt VARNISHLOG 1
.Os
.Sh NAME
@@ -44,6 +44,7 @@
.Op Fl d
.Op Fl I Ar regex
.Op Fl i Ar tag
+.Op Fl k Ar keep
.Op Fl n Ar varnish_name
.Op Fl o
.Op Fl P Ar file
@@ -108,6 +109,10 @@
nor
.Fl i
is specified, all log entries are included.
+.It Fl k Ar num
+Only show the first
+.Nm num
+log records.
.It Fl n
Specifies the name of the
.Nm varnishd
Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h 2008-03-08 16:59:38 UTC (rev 2574)
+++ trunk/varnish-cache/include/varnishapi.h 2008-03-09 15:14:04 UTC (rev 2575)
@@ -44,8 +44,8 @@
typedef int vsl_handler(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr);
#define VSL_S_CLIENT (1 << 0)
#define VSL_S_BACKEND (1 << 1)
-#define VSL_ARGS "bCcdI:i:r:s:X:x:"
-#define VSL_USAGE "[-bCcd] [-i tag] [-I regexp] [-r file] [-s skip] [-X regexp] [-x tag]"
+#define VSL_ARGS "bCcdI:i:k:r:s:X:x:"
+#define VSL_USAGE "[-bCcd] [-i tag] [-I regexp] [-k keep] [-r file] [-s skip] [-X regexp] [-x tag]"
vsl_handler VSL_H_Print;
struct VSL_data;
struct VSL_data *VSL_New(void);
Modified: trunk/varnish-cache/lib/libvarnishapi/shmlog.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/shmlog.c 2008-03-08 16:59:38 UTC (rev 2574)
+++ trunk/varnish-cache/lib/libvarnishapi/shmlog.c 2008-03-09 15:14:04 UTC (rev 2575)
@@ -87,6 +87,7 @@
regex_t *regexcl;
unsigned long skip;
+ unsigned long keep;
};
#ifndef MAP_HASSEMAPHORE
@@ -297,6 +298,9 @@
if (vd->skip) {
--vd->skip;
continue;
+ } else if (vd->keep) {
+ if (--vd->keep == 0)
+ return (0);
}
if (vd->map[p[SHMLOG_TAG]] & M_SELECT) {
*pp = p;
@@ -501,7 +505,26 @@
}
return (1);
}
+/*--------------------------------------------------------------------*/
+static int
+vsl_k_arg(struct VSL_data *vd, const char *opt)
+{
+ char *end;
+
+ CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+ if (*opt == '\0') {
+ fprintf(stderr, "number required for -k\n");
+ return (-1);
+ }
+ vd->keep = strtoul(opt, &end, 10);
+ if (*end != '\0') {
+ fprintf(stderr, "invalid number for -k\n");
+ return (-1);
+ }
+ return (1);
+}
+
/*--------------------------------------------------------------------*/
int
@@ -518,6 +541,7 @@
case 'I': case 'X': return (vsl_IX_arg(vd, opt, arg));
case 'C': vd->regflags = REG_ICASE; return (1);
case 's': return (vsl_s_arg(vd, opt));
+ case 'k': return (vsl_k_arg(vd, opt));
default:
return (0);
}
More information about the varnish-commit
mailing list