Home > Enterprise >  Time taken by the request in jetty 10 logging
Time taken by the request in jetty 10 logging

Time:10-14

This is follow up question for configure jetty logging. Is there any attribute that gives the time taken by the request?

123.4.5.6 - - [27/Aug/2004:10:16:17 0000] "GET /jetty/tut/XmlConfiguration.html HTTP/1.1" 200 76793 "http://localhost:8080/jetty/tut/logging.html" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040614 Firefox/0.8"

The above params are already defined in the configure jetty logging. but I do not see any param that gives us the time taken by the request.

Note - it used to be called log latency in the jetty9 - jetty9 custom logging

CodePudding user response:

You will need to change the format string of CustomRequestLog to include the %T percent code. This is documented in the javadoc for CustomRequestLog. (see https://javadoc.io/doc/org.eclipse.jetty/jetty-server/latest/org.eclipse.jetty.server/org/eclipse/jetty/server/CustomRequestLog.html)

  • %T - The time taken to serve the request, in seconds.
  • %{UNIT}T - The time taken to serve the request, in a time unit given by UNIT. Valid units are ms for milliseconds, us for microseconds, and s for seconds. Using s gives the same result as %T without any format; using us gives the same result as %D.

If you are not using CustomRequestLog and extending RequestLog yourself you can get the latency yourself by doing:

long latency = System.currentTimeMillis() - request.getTimeStamp();
  • Related