Skip to content

Commit 486b80c

Browse files
committed
Use DateTimeFormatter.formatTo to directly append to StringBuilder
1 parent 9a04f35 commit 486b80c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

log4j-api/src/main/java/org/apache/logging/log4j/message/ParameterFormatter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ private static boolean appendDate(final Object o, final StringBuilder str) {
459459
if (!(o instanceof Date)) {
460460
return false;
461461
}
462-
str.append(DATE_FORMATTER.format(((Date) o).toInstant()));
462+
DATE_FORMATTER.formatTo(((Date) o).toInstant(), str);
463463
return true;
464464
}
465465

log4j-api/src/main/java/org/apache/logging/log4j/status/StatusData.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ public Throwable getThrowable() {
167167
@SuppressWarnings("DefaultCharset")
168168
public String getFormattedStatus() {
169169
final StringBuilder sb = new StringBuilder();
170-
final String formattedInstant =
171-
instantFormatter != null ? instantFormatter.format(instant) : instant.toString();
172-
sb.append(formattedInstant);
170+
// DateTimeFormatter.ISO_INSTANT is the default used in instant.toString()
171+
DateTimeFormatter formatterToUse = instantFormatter != null ? instantFormatter : DateTimeFormatter.ISO_INSTANT;
172+
formatterToUse.formatTo(instant, sb);
173173
sb.append(SPACE);
174174
sb.append(getThreadName());
175175
sb.append(SPACE);

0 commit comments

Comments
 (0)