[master] 56d17a6 Add new format %{VCL_Log:foo}x which output key:value from std.log() in VCL
Tollef Fog Heen
tfheen at varnish-cache.org
Mon Oct 31 14:37:32 CET 2011
commit 56d17a6dc795a8f61821e9edcaa04a57a3d13f00
Author: Lasse Karstensen <lasse at varnish-software.com>
Date: Mon Oct 31 14:28:10 2011 +0100
Add new format %{VCL_Log:foo}x which output key:value from std.log() in VCL
diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index 47e5e2a..f699d9b 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -108,6 +108,7 @@ static struct logline {
uint64_t bitmap; /* Bitmap for regex matches */
VTAILQ_HEAD(, hdr) req_headers; /* Request headers */
VTAILQ_HEAD(, hdr) resp_headers; /* Response headers */
+ VTAILQ_HEAD(, hdr) vcl_log; /* VLC_Log entries */
} **ll;
struct VSM_data *vd;
@@ -219,6 +220,19 @@ resp_header(struct logline *l, const char *name)
return NULL;
}
+static char *
+vcl_log(struct logline *l, const char *name)
+{
+ struct hdr *h;
+ VTAILQ_FOREACH(h, &l->vcl_log, list) {
+ if (strcasecmp(h->key, name) == 0) {
+ return h->value;
+ break;
+ }
+ }
+ return NULL;
+}
+
static void
clean_logline(struct logline *lp)
{
@@ -245,6 +259,12 @@ clean_logline(struct logline *lp)
freez(h->value);
freez(h);
}
+ VTAILQ_FOREACH_SAFE(h, &lp->vcl_log, list, h2) {
+ VTAILQ_REMOVE(&lp->vcl_log, h, list);
+ freez(h->key);
+ freez(h->value);
+ freez(h);
+ }
#undef freez
memset(lp, 0, sizeof *lp);
}
@@ -465,6 +485,25 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec,
}
break;
+ case SLT_VCL_Log:
+ if(!lp->active)
+ break;
+
+ split = strchr(ptr, ':');
+ if (split == NULL)
+ break;
+
+ struct hdr *h;
+ h = malloc(sizeof(struct hdr));
+ AN(h);
+ AN(split);
+
+ h->key = trimline(ptr, split);
+ h->value = trimline(split+1, end);
+
+ VTAILQ_INSERT_HEAD(&lp->vcl_log, h, list);
+ break;
+
case SLT_VCL_call:
if(!lp->active)
break;
@@ -718,6 +757,14 @@ h_ncsa(void *priv, enum VSL_tag_e tag, unsigned fd,
VSB_cat(os, (lp->df_handling ? lp->df_handling : "-"));
p = tmp;
break;
+ } else if (strncmp(fname, "VCL_Log:", 8) == 0) {
+ // support pulling entries logged with std.log() into output.
+ // Format: %{VCL_Log:keyname}x
+ // Logging: std.log("keyname:value")
+ h = vcl_log(lp, fname+8);
+ VSB_cat(os, h ? h : "-");
+ p = tmp;
+ break;
}
default:
fprintf(stderr, "Unknown format starting at: %s\n", --p);
diff --git a/doc/sphinx/reference/varnishncsa.rst b/doc/sphinx/reference/varnishncsa.rst
index e654e37..ddb6538 100644
--- a/doc/sphinx/reference/varnishncsa.rst
+++ b/doc/sphinx/reference/varnishncsa.rst
@@ -116,6 +116,10 @@ The following options are available:
Varnish:handling
How the request was handled, whether it was a
cache hit, miss, pass, pipe or error.
+
+ VCL_Log:key
+ Output value set by std.log("key=value") in VCL.
+
-m tag:regex only list records where tag matches regex. Multiple
-m options are AND-ed together.
More information about the varnish-commit
mailing list