This is an automated email from the ASF dual-hosted git repository. schultz pushed a commit to branch 11.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit e3d132954a03b5d1fc39ef3d52a94f9a3db8b31a Author: minjund <[email protected]> AuthorDate: Fri Sep 26 00:17:34 2025 +0900 refactor: formatter refactoring --- java/org/apache/juli/JsonFormatter.java | 9 +-------- java/org/apache/juli/OneLineFormatter.java | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/java/org/apache/juli/JsonFormatter.java b/java/org/apache/juli/JsonFormatter.java index 2d07fb29d8..dc359ae4e0 100644 --- a/java/org/apache/juli/JsonFormatter.java +++ b/java/org/apache/juli/JsonFormatter.java @@ -65,14 +65,7 @@ public class JsonFormatter extends OneLineFormatter { // Thread sb.append("\"thread\": \""); - final String threadName = Thread.currentThread().getName(); - if (threadName != null && threadName.startsWith(AsyncFileHandler.THREAD_PREFIX)) { - // If using the async handler can't get the thread name from the - // current thread. - sb.append(getThreadName(record.getLongThreadID())); - } else { - sb.append(threadName); - } + sb.append(resolveThreadName(record)); sb.append("\", "); // Source diff --git a/java/org/apache/juli/OneLineFormatter.java b/java/org/apache/juli/OneLineFormatter.java index b0089014b1..96385602e9 100644 --- a/java/org/apache/juli/OneLineFormatter.java +++ b/java/org/apache/juli/OneLineFormatter.java @@ -50,12 +50,12 @@ public class OneLineFormatter extends Formatter { /** * The size of our global date format cache */ - private static final int globalCacheSize = 30; + private static final int GLOBAL_CACHE_SIZE = 30; /** * The size of our thread local date format cache */ - private static final int localCacheSize = 5; + private static final int LOCAL_CACHE_SIZE = 5; /** * Thread local date format cache. @@ -99,9 +99,9 @@ public class OneLineFormatter extends Formatter { cachedTimeFormat = timeFormat; } - final DateFormatCache globalDateCache = new DateFormatCache(globalCacheSize, cachedTimeFormat, null); + final DateFormatCache globalDateCache = new DateFormatCache(GLOBAL_CACHE_SIZE, cachedTimeFormat, null); localDateCache = - ThreadLocal.withInitial(() -> new DateFormatCache(localCacheSize, cachedTimeFormat, globalDateCache)); + ThreadLocal.withInitial(() -> new DateFormatCache(LOCAL_CACHE_SIZE, cachedTimeFormat, globalDateCache)); } @@ -129,14 +129,7 @@ public class OneLineFormatter extends Formatter { // Thread sb.append(' '); sb.append('['); - final String threadName = Thread.currentThread().getName(); - if (threadName != null && threadName.startsWith(AsyncFileHandler.THREAD_PREFIX)) { - // If using the async handler can't get the thread name from the - // current thread. - sb.append(getThreadName(record.getLongThreadID())); - } else { - sb.append(threadName); - } + sb.append(resolveThreadName(record)); sb.append(']'); // Source @@ -164,6 +157,17 @@ public class OneLineFormatter extends Formatter { return sb.toString(); } + protected String resolveThreadName(LogRecord record) { + final String threadName = Thread.currentThread().getName(); + if (threadName != null && threadName.startsWith(AsyncFileHandler.THREAD_PREFIX)) { + // If using the async handler can't get the thread name from the + // current thread. + return getThreadName(record.getLongThreadID()); + } else { + return threadName; + } + } + protected void addTimestamp(StringBuilder buf, long timestamp) { String cachedTimeStamp = localDateCache.get().getFormat(timestamp); if (millisHandling == MillisHandling.NONE) { --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
