Commit d5117f53 authored by Lasse Karstensen's avatar Lasse Karstensen Committed by Tollef Fog Heen

Add new format %{VCL_Log:foo}x which output key:value from std.log() in VCL

parent d04a8fb1
......@@ -105,6 +105,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;
......@@ -216,6 +217,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)
{
......@@ -242,6 +256,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);
}
......@@ -462,6 +482,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;
......@@ -715,6 +754,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);
......
......@@ -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.
......
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