This is an automated email from the ASF dual-hosted git repository. schultz pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push: new a7e9d7da69 Add support for timescales with time-taken access log token. (#721) a7e9d7da69 is described below commit a7e9d7da695f0f0de8d4a5494e1dc655f20cf62f Author: Christopher Schultz <ch...@christopherschultz.net> AuthorDate: Fri Apr 26 13:17:57 2024 -0400 Add support for timescales with time-taken access log token. (#721) Add support for timescales with time-taken access log token. Add support for nanosecond and fractional-second timescales. --- .../catalina/valves/AbstractAccessLogValve.java | 32 +++++++++++++++++++--- .../catalina/valves/ExtendedAccessLogValve.java | 14 +++++++++- webapps/docs/changelog.xml | 5 ++++ webapps/docs/config/valve.xml | 9 ++++-- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/java/org/apache/catalina/valves/AbstractAccessLogValve.java b/java/org/apache/catalina/valves/AbstractAccessLogValve.java index 5c4e67dde6..286647cfed 100644 --- a/java/org/apache/catalina/valves/AbstractAccessLogValve.java +++ b/java/org/apache/catalina/valves/AbstractAccessLogValve.java @@ -1316,6 +1316,19 @@ public abstract class AbstractAccessLogValve extends ValveBase implements Access buf.append(Long.toString(TimeUnit.NANOSECONDS.toSeconds(time))); } }, + SECONDS_FRACTIONAL { + @Override + public void append(CharArrayWriter buf, long time) { + time = time / 1000000; // Convert to millis + buf.append(Long.toString(time / 1000)); + buf.append('.'); + int remains = (int) (time % 1000); + buf.append(Long.toString(remains / 100)); + remains = remains % 100; + buf.append(Long.toString(remains / 10)); + buf.append(Long.toString(remains % 10)); + } + }, MILLISECONDS { @Override public void append(CharArrayWriter buf, long time) { @@ -1327,6 +1340,12 @@ public abstract class AbstractAccessLogValve extends ValveBase implements Access public void append(CharArrayWriter buf, long time) { buf.append(Long.toString(TimeUnit.NANOSECONDS.toMicros(time))); } + }, + NANOSECONDS { + @Override + public void append(CharArrayWriter buf, long time) { + buf.append(Long.toString(time)); + } }; /** @@ -1337,10 +1356,11 @@ public abstract class AbstractAccessLogValve extends ValveBase implements Access */ public abstract void append(CharArrayWriter buf, long time); } + private final Style style; /** - * Create a new ElapsedTimeElement that will log the time in the specified style. + * Creates a new ElapsedTimeElement that will log the time in the specified style. * * @param style The elapsed-time style to use. */ @@ -1760,10 +1780,14 @@ public abstract class AbstractAccessLogValve extends ValveBase implements Access return new DateAndTimeElement(name); case 'T': // ms for milliseconds, us for microseconds, and s for seconds - if ("ms".equals(name)) { - return new ElapsedTimeElement(false, true); + if ("ns".equals(name)) { + return new ElapsedTimeElement(ElapsedTimeElement.Style.NANOSECONDS); } else if ("us".equals(name)) { - return new ElapsedTimeElement(true, false); + return new ElapsedTimeElement(ElapsedTimeElement.Style.MICROSECONDS); + } else if ("ms".equals(name)) { + return new ElapsedTimeElement(ElapsedTimeElement.Style.MILLISECONDS); + } else if ("fracsec".equals(name)) { + return new ElapsedTimeElement(ElapsedTimeElement.Style.SECONDS_FRACTIONAL); } else { return new ElapsedTimeElement(false, false); } diff --git a/java/org/apache/catalina/valves/ExtendedAccessLogValve.java b/java/org/apache/catalina/valves/ExtendedAccessLogValve.java index c75e41dc01..8b9c9f090c 100644 --- a/java/org/apache/catalina/valves/ExtendedAccessLogValve.java +++ b/java/org/apache/catalina/valves/ExtendedAccessLogValve.java @@ -535,7 +535,19 @@ public class ExtendedAccessLogValve extends AccessLogValve { if (tokenizer.hasSubToken()) { String nextToken = tokenizer.getToken(); if ("taken".equals(nextToken)) { - return new ElapsedTimeElement(false, false); + nextToken = tokenizer.getToken(); + + if ("ns".equals(nextToken)) { + return new ElapsedTimeElement(ElapsedTimeElement.Style.NANOSECONDS); + } else if("us".equals(nextToken)) { + return new ElapsedTimeElement(ElapsedTimeElement.Style.MICROSECONDS); + } else if ("ms".equals(nextToken)) { + return new ElapsedTimeElement(ElapsedTimeElement.Style.MILLISECONDS); + } else if ("fracsec".equals(nextToken)) { + return new ElapsedTimeElement(ElapsedTimeElement.Style.SECONDS_FRACTIONAL); + } else { + return new ElapsedTimeElement(ElapsedTimeElement.Style.SECONDS); + } } } else { return new TimeElement(); diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 72c9f3c86f..b022f03249 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -121,6 +121,11 @@ Re-factor ElapsedTimeElement in AbstractAccessLogValve to use a customizable style. (schultz) </add> + <add> + Add more timescale options to AccessLogValve and ExtendedAccessLogValve. + Allow timescales to apply to "time-taken" token in ExtendedAccessLogValve. + (schultz) + </add> <fix> Fix WebDAV lock null (locks for non existing resources) thread safety and removal. (remm) diff --git a/webapps/docs/config/valve.xml b/webapps/docs/config/valve.xml index 800da1b323..390848a3c3 100644 --- a/webapps/docs/config/valve.xml +++ b/webapps/docs/config/valve.xml @@ -338,8 +338,9 @@ <li><b><code>%{xxx}t</code></b> write timestamp at the end of the request formatted using the enhanced SimpleDateFormat pattern <code>xxx</code></li> <li><b><code>%{xxx}T</code></b> write time taken to process the request using unit <code>xxx</code> - where valid units are <code>ms</code> for milliseconds, <code>us</code> for microseconds, - and <code>s</code> for seconds. <code>%{s}T</code> is equivalent to <code>%T</code> as well + where valid units are <code>ns</code> for nanoseconds, <code>us</code> for microseconds, + <code>ms</code> for milliseconds, <code>fracsec</code> for fractional seconds, or <code>s</code> for whole seconds. + <code>%{s}T</code> is equivalent to <code>%T</code> as well as <code>%{us}T</code> is equivalent to <code>%D</code>.</li> </ul> @@ -465,7 +466,9 @@ <li><b>s-ip</b> - Local IP address</li> <li><b>sc-status</b> - HTTP status code of the response</li> <li><b>time</b> - Time the request was served in HH:mm:ss format for GMT</li> - <li><b>time-taken</b> - Time (in seconds) taken to serve the request</li> + <li><b>time-taken</b> - Time (in seconds) taken to serve the request. Can also use the + suffixes <code>-ns</code> for nanoseconds, <code>-us</code> for microseconds, + <code>-ms</code> for milliseconds, <code>-fracsec</code> for fractional seconds.</li> <li><b>x-threadname</b> - Current request thread name (can compare later with stacktraces)</li> </ul> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org