On 19/04/2024 13:12, schu...@apache.org wrote:
This is an automated email from the ASF dual-hosted git repository.
schultz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit d3482c35bf144cc891dfa325b2f2f50460708c23
Author: Christopher Schultz <ch...@christopherschultz.net>
AuthorDate: Thu Apr 18 10:22:16 2024 -0400
Re-factor ElapsedTimeElement to use a customizable Style
How is this customizable?
This seems to add complexity to somewhere we probably want to keep
things simple.
Mark
---
.../catalina/valves/AbstractAccessLogValve.java | 52 +++++++++++++++++-----
webapps/docs/changelog.xml | 4 ++
2 files changed, 44 insertions(+), 12 deletions(-)
diff --git a/java/org/apache/catalina/valves/AbstractAccessLogValve.java
b/java/org/apache/catalina/valves/AbstractAccessLogValve.java
index e13bb9e5ac..0576b83442 100644
--- a/java/org/apache/catalina/valves/AbstractAccessLogValve.java
+++ b/java/org/apache/catalina/valves/AbstractAccessLogValve.java
@@ -1307,8 +1307,44 @@ public abstract class AbstractAccessLogValve extends
ValveBase implements Access
* write time taken to process the request - %D, %T
*/
protected static class ElapsedTimeElement implements AccessLogElement {
- private final boolean micros;
- private final boolean millis;
+ enum Style {
+ SECONDS {
+ @Override
+ public void append(CharArrayWriter buf, long time) {
+
buf.append(Long.toString(TimeUnit.NANOSECONDS.toSeconds(time)));
+ }
+ },
+ MILLISECONDS {
+ @Override
+ public void append(CharArrayWriter buf, long time) {
+
buf.append(Long.toString(TimeUnit.NANOSECONDS.toMillis(time)));
+ }
+ },
+ MICROSECONDS {
+ @Override
+ public void append(CharArrayWriter buf, long time) {
+
buf.append(Long.toString(TimeUnit.NANOSECONDS.toMicros(time)));
+ }
+ };
+
+ /**
+ * Append the time to the buffer in the appropriate format.
+ *
+ * @param buf The buffer to append to.
+ * @param time The time to log in nanoseconds.
+ */
+ 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.
+ *
+ * @param style The elapsed-time style to use.
+ */
+ public ElapsedTimeElement(Style style) {
+ this.style = style;
+ }
/**
* @param micros <code>true</code>, write time in microseconds - %D
@@ -1316,20 +1352,12 @@ public abstract class AbstractAccessLogValve extends
ValveBase implements Access
* time in seconds - %T
*/
public ElapsedTimeElement(boolean micros, boolean millis) {
- this.micros = micros;
- this.millis = millis;
+ this(micros ? Style.MICROSECONDS : millis ? Style.MILLISECONDS :
Style.SECONDS);
}
@Override
public void addElement(CharArrayWriter buf, Date date, Request
request, Response response, long time) {
- if (micros) {
- buf.append(Long.toString(TimeUnit.NANOSECONDS.toMicros(time)));
- } else if (millis) {
- buf.append(Long.toString(TimeUnit.NANOSECONDS.toMillis(time)));
- } else {
- // second
-
buf.append(Long.toString(TimeUnit.NANOSECONDS.toSeconds(time)));
- }
+ style.append(buf, time);
}
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index bda2e5d98c..f6eacba634 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -133,6 +133,10 @@
dispatch is now performed rather than completing the request using the
error page mechanism. (markt)
</fix>
+ <add>
+ Re-factor ElapsedTimeElement in AbstractAccessLogValve to use a
customizable
+ style. (schultz)
+ </add>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org