Re: (tomcat) 02/02: Re-factor ElapsedTimeElement to use a customizable Style
On 19/04/2024 13:31, Mark Thomas wrote: 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 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. Never mind. I think you meant extensible. I can see what you are trying to do in the PR that adds ns etc. Mark 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 true, 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) + + Re-factor ElapsedTimeElement in AbstractAccessLogValve to use a customizable + style. (schultz) + - 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 - To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional
Re: (tomcat) 02/02: Re-factor ElapsedTimeElement to use a customizable Style
Mark, On 4/19/24 08:31, Mark Thomas wrote: 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 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. It was preparation for this PR: https://github.com/apache/tomcat/pull/721 The use of two-booleans means that we could support only 4 possible formats where one of them didn't make any sense (i.e. microseconds=true && milliseconds == true). -chris --- .../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 true, 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) + + Re-factor ElapsedTimeElement in AbstractAccessLogValve to use a customizable + style. (schultz) + - 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
Re: (tomcat) 02/02: Re-factor ElapsedTimeElement to use a customizable Style
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 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 true, 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) + +Re-factor ElapsedTimeElement in AbstractAccessLogValve to use a customizable +style. (schultz) + - 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
(tomcat) 02/02: Re-factor ElapsedTimeElement to use a customizable Style
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 commit 1448eccfd86ef6385e0af629c138ab28405ed6c2 Author: Christopher Schultz AuthorDate: Thu Apr 18 10:22:16 2024 -0400 Re-factor ElapsedTimeElement to use a customizable Style --- .../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 df942110ab..03acb492fa 100644 --- a/java/org/apache/catalina/valves/AbstractAccessLogValve.java +++ b/java/org/apache/catalina/valves/AbstractAccessLogValve.java @@ -1309,8 +1309,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 true, write time in microseconds - %D @@ -1318,20 +1354,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 e724ed92a6..3a295c0937 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -135,6 +135,10 @@ dispatch is now performed rather than completing the request using the error page mechanism. (markt) + +Re-factor ElapsedTimeElement in AbstractAccessLogValve to use a customizable +style. (schultz) + - To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org
(tomcat) 02/02: Re-factor ElapsedTimeElement to use a customizable Style
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 AuthorDate: Thu Apr 18 10:22:16 2024 -0400 Re-factor ElapsedTimeElement to use a customizable Style --- .../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 true, 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) + +Re-factor ElapsedTimeElement in AbstractAccessLogValve to use a customizable +style. (schultz) + - To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org