This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new e67a094ca0 Reduce duplication
e67a094ca0 is described below
commit e67a094ca097fab179bec521505fc9fae095939c
Author: Mark Thomas <[email protected]>
AuthorDate: Thu May 7 14:27:46 2026 +0100
Reduce duplication
---
.../catalina/valves/AbstractAccessLogValve.java | 32 ++++++++++++++--------
.../catalina/valves/ExtendedAccessLogValve.java | 12 +-------
2 files changed, 21 insertions(+), 23 deletions(-)
diff --git a/java/org/apache/catalina/valves/AbstractAccessLogValve.java
b/java/org/apache/catalina/valves/AbstractAccessLogValve.java
index 8e3ed4a3bd..e1bd7b0e93 100644
--- a/java/org/apache/catalina/valves/AbstractAccessLogValve.java
+++ b/java/org/apache/catalina/valves/AbstractAccessLogValve.java
@@ -1680,6 +1680,25 @@ public abstract class AbstractAccessLogValve extends
ValveBase implements Access
this.style = style;
}
+ /**
+ * Creates a new ElapsedTimeElement that will log the time in the
specified style.
+ *
+ * @param styleName The name of the elapsed-time style to use.
+ */
+ public ElapsedTimeElement(String styleName) {
+ if ("ns".equals(styleName)) {
+ this.style = ElapsedTimeElement.Style.NANOSECONDS;
+ } else if ("us".equals(styleName)) {
+ this.style = ElapsedTimeElement.Style.MICROSECONDS;
+ } else if ("ms".equals(styleName)) {
+ this.style = ElapsedTimeElement.Style.MILLISECONDS;
+ } else if ("fracsec".equals(styleName)) {
+ this.style = ElapsedTimeElement.Style.SECONDS_FRACTIONAL;
+ } else {
+ this.style = ElapsedTimeElement.Style.SECONDS;
+ }
+ }
+
@Override
public void addElement(CharArrayWriter buf, Request request, Response
response, long time) {
style.append(buf, time);
@@ -2280,18 +2299,7 @@ public abstract class AbstractAccessLogValve extends
ValveBase implements Access
case 't':
return new DateAndTimeElement(name);
case 'T':
- // ms for milliseconds, us for microseconds, and s for seconds
- if ("ns".equals(name)) {
- return new
ElapsedTimeElement(ElapsedTimeElement.Style.NANOSECONDS);
- } else if ("us".equals(name)) {
- 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(ElapsedTimeElement.Style.SECONDS);
- }
+ return new ElapsedTimeElement(name);
default:
return new StringElement("???");
}
diff --git a/java/org/apache/catalina/valves/ExtendedAccessLogValve.java
b/java/org/apache/catalina/valves/ExtendedAccessLogValve.java
index db0b01ffe3..965330f2f2 100644
--- a/java/org/apache/catalina/valves/ExtendedAccessLogValve.java
+++ b/java/org/apache/catalina/valves/ExtendedAccessLogValve.java
@@ -640,17 +640,7 @@ public class ExtendedAccessLogValve extends AccessLogValve
{
if ("taken".equals(nextToken)) {
if (tokenizer.hasSubToken()) {
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);
- }
+ return new ElapsedTimeElement(nextToken);
} else {
return new
ElapsedTimeElement(ElapsedTimeElement.Style.SECONDS);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]