This is an automated email from the ASF dual-hosted git repository.
rjung pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 4516a266ed Switch from lambda to new parametrized CharElement.
4516a266ed is described below
commit 4516a266ed9b8242b443d74f14b324721f73c836
Author: Rainer Jung <[email protected]>
AuthorDate: Thu Apr 27 10:09:29 2023 +0200
Switch from lambda to new parametrized CharElement.
It is more consistent with all other output
and eases backports.
---
.../apache/catalina/valves/JsonAccessLogValve.java | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/java/org/apache/catalina/valves/JsonAccessLogValve.java
b/java/org/apache/catalina/valves/JsonAccessLogValve.java
index 2a56d1763e..bd4fb91da4 100644
--- a/java/org/apache/catalina/valves/JsonAccessLogValve.java
+++ b/java/org/apache/catalina/valves/JsonAccessLogValve.java
@@ -93,11 +93,27 @@ public class JsonAccessLogValve extends AccessLogValve {
PATTERNS = Collections.unmodifiableMap(pattern2AttributeName);
}
+ /**
+ * write any char
+ */
+ protected static class CharElement implements AccessLogElement {
+ private final char ch;
+
+ public CharElement(char ch) {
+ this.ch = ch;
+ }
+
+ @Override
+ public void addElement(CharArrayWriter buf, Date date, Request
request, Response response, long time) {
+ buf.write(ch);
+ }
+ }
+
@Override
protected AccessLogElement[] createLogElements() {
List<AccessLogElement> logElements = new
ArrayList<>(Arrays.asList(super.createLogElements()));
ListIterator<AccessLogElement> lit = logElements.listIterator();
- lit.add((buf, date, req, resp, time) -> buf.write('{'));
+ lit.add(new CharElement('{'));
while (lit.hasNext()) {
AccessLogElement logElement = lit.next();
// remove all other elements, like StringElements
@@ -105,12 +121,12 @@ public class JsonAccessLogValve extends AccessLogValve {
lit.remove();
continue;
}
- lit.add((buf, date, req, resp, time) -> buf.write(','));
+ lit.add(new CharElement(','));
}
// remove last comma again
lit.previous();
lit.remove();
- lit.add((buf, date, req, resp, time) -> buf.write('}'));
+ lit.add(new CharElement('}'));
return logElements.toArray(new AccessLogElement[logElements.size()]);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]