Github user cakofony commented on a diff in the pull request:
https://github.com/apache/logging-log4j2/pull/205#discussion_r208705419
--- Diff:
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
---
@@ -204,15 +206,19 @@ public void setLoggerName(final String loggerName) {
@Override
public Message getMessage() {
if (message == null) {
- return messageText == null ? EMPTY : this;
+ return (messageText == null && messageContentFormatter ==
null) ? EMPTY : this;
}
return message;
}
public void setMessage(final Message msg) {
if (msg instanceof ReusableMessage) {
final ReusableMessage reusable = (ReusableMessage) msg;
- reusable.formatTo(getMessageTextForWriting());
+ if (Constants.FORMAT_MESSAGES_IN_BACKGROUND && msg instanceof
MessageContentFormatterProvider) {
+ this.messageContentFormatter =
((MessageContentFormatterProvider) msg).getMessageContentFormatter();
--- End diff --
I don't think this quite works for the AsyncLogger case. Using mixed
sync/async loggers via configuration, message data flows:
1. ReusableMessage.init(<data>)
2. MutableLogEvent.initFrom(<data, including the reusable message>)
3. MutableLogEvent may be logged to synchronous appenders, then data is
copied to the background thread for asynchronous format/append operations. This
is done by initializing another MutableLogEvent (on the disruptor ringbuffer)
from the existing MutableLogEvent, see AsyncLoggerConfigDisruptor:174.
We can fix this by making MutableLogEvent and RingBufferLogEvent both
implement MessageContentFormatterProvider, and check `messageContentFormatter`
for null in which case `reusable.formatTo(getMessageTextForWriting());` should
be invoked.
---