[4.1] 017e6d1 New format of VSL formatter in varnishncsa

PÃ¥l Hermunn Johansen hermunn at varnish-software.com
Fri Apr 29 16:51:06 CEST 2016


commit 017e6d12cad04023b3fbb7809d60076f5a35d89d
Author: Pål Hermunn Johansen <hermunn at varnish-software.com>
Date:   Fri Apr 29 16:29:38 2016 +0200

    New format of VSL formatter in varnishncsa
    
    Updated formatter %{VSL:tag}x to mirror the VQL. The documentation has
    been updated accordingly.

diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index 47e6fc7..76eea41 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -598,7 +598,7 @@ addf_auth(const char *str)
 static void
 parse_x_format(char *buf)
 {
-	char *r, *s, c;
+	char *e, *r, *s;
 	int slt;
 	long i;
 
@@ -628,34 +628,43 @@ parse_x_format(char *buf)
 	}
 	if (!strncmp(buf, "VSL:", 4)) {
 		buf += 4;
-		r = buf;
-		while(*r != ':' && *r != '\0')
-			r++;
-		c = *r;
-		*r = '\0';
+		e = buf;
+		while(*e != '\0')
+			e++;
+		if (e == buf) {
+			VUT_Error(1, "Missing tag in VSL:");
+		}
+		if (e[-1] == ']') {
+			r = e - 1;
+			while (r > buf && *r != '[')
+				r--;
+			if (r == buf || r[1] == ']')
+				VUT_Error(1, "Syntax error: VSL:%s", buf);
+			e[-1] = '\0';
+			i = strtol(r + 1, &s, 10);
+			if (s != e - 1)
+				VUT_Error(1, "Syntax error: VSL:%s]", buf);
+			if (i <= 0)
+				VUT_Error(1,
+				    "Syntax error. Field specifyer must be"
+				    " positive: %s]",
+				    buf);
+			if (i > INT_MAX) {
+				VUT_Error(1,
+				    "Field specifier %ld for the tag VSL:%s]"
+				    " is probably too high",
+				    i, buf);
+			}
+			*r = '\0';
+		} else
+			i = 0;
 		slt = VSL_Name2Tag(buf, -1);
 		if (slt == -2)
 			VUT_Error(1, "Tag not unique: %s", buf);
 		if (slt == -1)
 			VUT_Error(1, "Unknown log tag: %s", buf);
 		assert(slt >= 0);
-		if (c) {
-			i = strtol(r + 1, &s, 10);
-			if (*s)
-				VUT_Error(1,
-				    "Not a number: %s (see VSL:%s)",
-				    r + 1, buf);
-			if (i < 0)
-				VUT_Error(1,
-				    "Illegal '-' in field specifier for VSL:%s",
-				    buf);
-		} else
-			i = 0;
-		if (i > INT_MAX) {
-			VUT_Error(1, "Field specifier %ld for the tag VSL:%s"
-			    " is probably too high",
-			    i, buf);
-		}
+
 		addf_vsl(slt, i);
 		return;
 	}
diff --git a/doc/sphinx/reference/varnishncsa.rst b/doc/sphinx/reference/varnishncsa.rst
index d0d0dc5..381cdd4 100644
--- a/doc/sphinx/reference/varnishncsa.rst
+++ b/doc/sphinx/reference/varnishncsa.rst
@@ -176,13 +176,15 @@ Supported formatters are:
   VCL_Log:key
     Output value set by std.log("key:value") in VCL.
 
-  VSL:key[:field]
-    The value of the varnishlog entry with the given key.  If field is
-    specified, only the selected part is shown.  Specifying ":0" is
-    equivalent to not specifying a field, where the entire field is
-    printed.  Defaults to "-" (without the quotes) when the key is not
-    seen, or when the field is out of bounds.  If a key appears several
-    times in a given transaction, only the first occurrence is used.
+  VSL:tag or VSL:tag[field]
+
+    The value of the varnishlog entry with the given tag.  If field is
+    specified, only the selected part is shown.  Defaults to "-"
+    (without the quotes) when the key is not seen, or when the field
+    is out of bounds.  If a key appears several times in a single
+    transaction, only the first occurrence is used.  Example: The
+    formatter %{VSL:Begin[2]}x will print the second field of the
+    Begin tag, which is the vxid of the parent transaction.
 
 SIGNALS
 =======



More information about the varnish-commit mailing list