This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-logging.git
commit 9a44202650a94bbb29f77022f741ba0ab5c100dc Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Feb 28 08:52:35 2025 -0500 Simplify static initialization of SimpleLog Javadoc --- .../org/apache/commons/logging/impl/SimpleLog.java | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/apache/commons/logging/impl/SimpleLog.java b/src/main/java/org/apache/commons/logging/impl/SimpleLog.java index 19d5cce..db182fb 100644 --- a/src/main/java/org/apache/commons/logging/impl/SimpleLog.java +++ b/src/main/java/org/apache/commons/logging/impl/SimpleLog.java @@ -108,6 +108,9 @@ public class SimpleLog implements Log, Serializable { * in 1.1.1 to fix an existing thread safety bug (SimpleDateFormat.format * is not thread-safe). * </p> + * <p> + * Statically initialized to a {@link SimpleDateFormat}. + * </p> */ static protected DateFormat dateFormatter; @@ -142,20 +145,13 @@ public class SimpleLog implements Log, Serializable { } catch (final IOException ignore) { // Ignore } - showLogName = getBooleanProperty(systemPrefix + "showlogname", showLogName); showShortName = getBooleanProperty(systemPrefix + "showShortLogname", showShortName); showDateTime = getBooleanProperty(systemPrefix + "showdatetime", showDateTime); - if (showDateTime) { - dateTimeFormat = getStringProperty(systemPrefix + "dateTimeFormat", dateTimeFormat); - try { - dateFormatter = new SimpleDateFormat(dateTimeFormat); - } catch (final IllegalArgumentException e) { - // If the format pattern is invalid - use the default format - dateTimeFormat = DEFAULT_DATE_TIME_FORMAT; - dateFormatter = new SimpleDateFormat(dateTimeFormat); - } + SimpleDateFormat simpleDateFormatter = getSimpleDateFormat(); + dateFormatter = simpleDateFormatter; + dateTimeFormat = simpleDateFormatter.toPattern(); } } @@ -210,6 +206,15 @@ public class SimpleLog implements Log, Serializable { }); } + private static SimpleDateFormat getSimpleDateFormat() { + try { + return new SimpleDateFormat(getStringProperty(systemPrefix + "dateTimeFormat", dateTimeFormat)); + } catch (final IllegalArgumentException e) { + // If the format pattern is invalid - use the default format + return new SimpleDateFormat(DEFAULT_DATE_TIME_FORMAT); + } + } + private static String getStringProperty(final String name) { String prop = null; try {