Search in sources :

Example 1 with ReusableMessage

use of org.apache.logging.log4j.message.ReusableMessage in project logging-log4j2 by apache.

the class Log4jLogEventTest method testToImmutableNotSame.

@Test
public void testToImmutableNotSame() {
    final LogEvent logEvent = new Log4jLogEvent.Builder().setMessage(new ReusableObjectMessage()).build();
    LogEvent immutable = logEvent.toImmutable();
    Assert.assertSame(logEvent, immutable);
    Assert.assertFalse(immutable.getMessage() instanceof ReusableMessage);
}
Also used : LogEvent(org.apache.logging.log4j.core.LogEvent) ReusableMessage(org.apache.logging.log4j.message.ReusableMessage) ReusableObjectMessage(org.apache.logging.log4j.message.ReusableObjectMessage) Test(org.junit.Test) ClockFactoryTest(org.apache.logging.log4j.core.util.ClockFactoryTest)

Example 2 with ReusableMessage

use of org.apache.logging.log4j.message.ReusableMessage in project logging-log4j2 by apache.

the class MutableLogEvent method setMessage.

public void setMessage(final Message msg) {
    if (msg instanceof ReusableMessage) {
        final ReusableMessage reusable = (ReusableMessage) msg;
        reusable.formatTo(getMessageTextForWriting());
        if (parameters != null) {
            parameters = reusable.swapParameters(parameters);
            parameterCount = reusable.getParameterCount();
        }
    } else {
        // if the Message instance is reused, there is no point in freezing its message here
        if (msg != null && !canFormatMessageInBackground(msg)) {
            // LOG4J2-763: ask message to freeze parameters
            msg.getFormattedMessage();
        }
        this.message = msg;
    }
}
Also used : ReusableMessage(org.apache.logging.log4j.message.ReusableMessage)

Example 3 with ReusableMessage

use of org.apache.logging.log4j.message.ReusableMessage in project logging-log4j2 by apache.

the class RingBufferLogEvent method setMessage.

private void setMessage(final Message msg) {
    if (msg instanceof ReusableMessage) {
        final ReusableMessage reusable = (ReusableMessage) msg;
        reusable.formatTo(getMessageTextForWriting());
        if (parameters != null) {
            parameters = reusable.swapParameters(parameters);
            parameterCount = reusable.getParameterCount();
        }
    } else {
        // if the Message instance is reused, there is no point in freezing its message here
        if (msg != null && !canFormatMessageInBackground(msg)) {
            // LOG4J2-763: ask message to freeze parameters
            msg.getFormattedMessage();
        }
        this.message = msg;
    }
}
Also used : ReusableMessage(org.apache.logging.log4j.message.ReusableMessage)

Aggregations

ReusableMessage (org.apache.logging.log4j.message.ReusableMessage)3 LogEvent (org.apache.logging.log4j.core.LogEvent)1 ClockFactoryTest (org.apache.logging.log4j.core.util.ClockFactoryTest)1 ReusableObjectMessage (org.apache.logging.log4j.message.ReusableObjectMessage)1 Test (org.junit.Test)1