Add option to log url request including query string
@@ -197,6 +197,7 @@ public class RequestLogger implements Route.Handler {
private static final char BL = '[';
private static final char BR = ']';
private static final char Q = '\"';
+ private static final char QUERY = '?';
private static Function<Request, String> ANNON = req -> DASH;
@@ -211,6 +212,8 @@ public class RequestLogger implements Route.Handler {
private boolean latency;
+ private boolean queryString;
+
private boolean extended;
/**
@@ -247,6 +250,10 @@ public class RequestLogger implements Route.Handler {
sb.append(Q).append(req.method());
sb.append(SP);
sb.append(req.path());
+ if (queryString && req.queryString().isPresent()) {
+ sb.append(QUERY);
+ sb.append(req.queryString().get());
+ }
sb.append(SP);
sb.append(req.protocol());
sb.append(Q).append(SP);
@@ -331,6 +338,16 @@ public class RequestLogger implements Route.Handler {
return this;
}
+ /**
+ * Log full path of the request including query string.
+ *
+ * @return This instance.
+ */
+ public RequestLogger queryString() {
+ this.queryString = true;
+ return this;
+ }
+
/**
* Append <code>Referer</code> and <code>User-Agent</code> entries to the NCSA line.
*
