From 30bf5dcb0dd7aea76b7d5a21cb69bfb073d00e16 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 14 Jul 2013 06:55:15 -0700 Subject: [PATCH] Do not using static finals for PID and format Update SimpleFormatter so that the PID and format can be different per formatter instance. --- .../bootstrap/logging/java/SimpleFormatter.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/logging/java/SimpleFormatter.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/logging/java/SimpleFormatter.java index 691fc53d78..9e1e17a3b2 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/logging/java/SimpleFormatter.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/logging/java/SimpleFormatter.java @@ -31,11 +31,11 @@ public class SimpleFormatter extends Formatter { private static final String DEFAULT_FORMAT = "[%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL] - %8$s %4$s [%7$s] --- %3$s: %5$s%6$s%n"; - private static String FORMAT = setOrUseDefault("LOG_FORMAT", DEFAULT_FORMAT); + private final String format = getOrUseDefault("LOG_FORMAT", DEFAULT_FORMAT); - private final Date date = new Date(); + private final String pid = getOrUseDefault("PID", "????"); - private static String PID = setOrUseDefault("PID", "????"); + private final Date date = new Date(); @Override public synchronized String format(LogRecord record) { @@ -44,8 +44,9 @@ public class SimpleFormatter extends Formatter { String message = formatMessage(record); String throwable = getThrowable(record); String thread = getThreadName(); - return String.format(FORMAT, this.date, source, record.getLoggerName(), record - .getLevel().getLocalizedName(), message, throwable, thread, PID); + return String.format(this.format, this.date, source, record.getLoggerName(), + record.getLevel().getLocalizedName(), message, throwable, thread, + this.pid); } private String getThrowable(LogRecord record) { @@ -65,7 +66,7 @@ public class SimpleFormatter extends Formatter { return (name == null ? "" : name); } - private static String setOrUseDefault(String key, String defaultValue) { + private static String getOrUseDefault(String key, String defaultValue) { String value = null; try { value = System.getenv(key);