Commit 150ecb15 authored by Dag Erling Smørgrav's avatar Dag Erling Smørgrav

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.


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2575 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 36c9b6ae
......@@ -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 @@ If neither
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
......
......@@ -44,8 +44,8 @@ int base64_decode(char *d, unsigned dlen, const char *s);
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);
......
......@@ -87,6 +87,7 @@ struct VSL_data {
regex_t *regexcl;
unsigned long skip;
unsigned long keep;
};
#ifndef MAP_HASSEMAPHORE
......@@ -297,6 +298,9 @@ VSL_NextLog(struct VSL_data *vd, unsigned char **pp)
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,6 +505,25 @@ vsl_s_arg(struct VSL_data *vd, const char *opt)
}
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);
}
/*--------------------------------------------------------------------*/
......@@ -518,6 +541,7 @@ VSL_Arg(struct VSL_data *vd, int arg, const char *opt)
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);
}
......
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