Skip to content

Commit 6812e5e

Browse files
committed
fix: document reason for getFormattedMessage call
Adds comments to explain the side effects of the `getFormattedMessage` calls.
1 parent c5091d6 commit 6812e5e

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ public <S> void forEachParameter(final ParameterConsumer<S> action, final S stat
129129
@Override
130130
public Message memento() {
131131
Message message = new ObjectMessage(obj);
132+
// Since `toString()` methods are not always pure functions and might depend on the thread and other context
133+
// values, we format the message and cache the result.
132134
message.getFormattedMessage();
133135
return message;
134136
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public <S> void forEachParameter(final ParameterConsumer<S> action, final S stat
115115
@Override
116116
public Message memento() {
117117
Message message = new ParameterizedMessage(messagePattern, getTrimmedParams());
118+
// Since `toString()` methods are not always pure functions and might depend on the thread and other context
119+
// values, we format the message and cache the result.
118120
message.getFormattedMessage();
119121
return message;
120122
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public <S> void forEachParameter(final ParameterConsumer<S> action, final S stat
8686
@Override
8787
public Message memento() {
8888
SimpleMessage message = new SimpleMessage(charSequence);
89+
// Since `toString()` methods are not always pure functions and might depend on the thread and other context
90+
// values, we format the message and cache the result.
8991
message.getFormattedMessage();
9092
return message;
9193
}

0 commit comments

Comments
 (0)