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 589fd9c23af4bf1a613faa98bfadc0f20297ab35 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 c2ad5382e1..7667193b1d 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.getThreadID())); - } 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 a6fa4eba39..57062d0a4e 100644 --- a/java/org/apache/juli/OneLineFormatter.java +++ b/java/org/apache/juli/OneLineFormatter.java @@ -51,12 +51,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. @@ -100,9 +100,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)); } @@ -130,14 +130,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.getThreadID())); - } else { - sb.append(threadName); - } + sb.append(resolveThreadName(record)); sb.append(']'); // Source @@ -165,6 +158,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.getThreadID()); + } 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]
