Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit 1533ae4

Browse files
committed
Add option to log url request including query string
1 parent aca3160 commit 1533ae4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

jooby/src/main/java/org/jooby/RequestLogger.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public class RequestLogger implements Route.Handler {
197197
private static final char BL = '[';
198198
private static final char BR = ']';
199199
private static final char Q = '\"';
200+
private static final char QUERY = '?';
200201

201202
private static Function<Request, String> ANNON = req -> DASH;
202203

@@ -211,6 +212,8 @@ public class RequestLogger implements Route.Handler {
211212

212213
private boolean latency;
213214

215+
private boolean queryString;
216+
214217
private boolean extended;
215218

216219
/**
@@ -247,6 +250,10 @@ public void handle(final Request req, final Response rsp) throws Throwable {
247250
sb.append(Q).append(req.method());
248251
sb.append(SP);
249252
sb.append(req.path());
253+
if (queryString && req.queryString().isPresent()) {
254+
sb.append(QUERY);
255+
sb.append(req.queryString().get());
256+
}
250257
sb.append(SP);
251258
sb.append(req.protocol());
252259
sb.append(Q).append(SP);
@@ -331,6 +338,16 @@ public RequestLogger latency() {
331338
return this;
332339
}
333340

341+
/**
342+
* Log full path of the request including query string.
343+
*
344+
* @return This instance.
345+
*/
346+
public RequestLogger queryString() {
347+
this.queryString = true;
348+
return this;
349+
}
350+
334351
/**
335352
* Append <code>Referer</code> and <code>User-Agent</code> entries to the NCSA line.
336353
*

0 commit comments

Comments
 (0)