Search in sources :

Example 86 with Message

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

the class LevelPatternConverterTest method testLevelMapWithLength.

@Test
public void testLevelMapWithLength() {
    final Message msg = new SimpleMessage("Hello");
    LogEvent event = // 
    Log4jLogEvent.newBuilder().setLoggerName(// 
    "MyLogger").setLevel(// 
    Level.DEBUG).setMessage(msg).build();
    final StringBuilder sb = new StringBuilder();
    LevelPatternConverter converter = LevelPatternConverter.newInstance(null);
    converter.format(event, sb);
    assertEquals(Level.DEBUG.toString(), sb.toString());
    final String[] opts = new String[] { "WARN=Warning, length=2" };
    converter = LevelPatternConverter.newInstance(opts);
    sb.setLength(0);
    converter.format(event, sb);
    assertEquals("DE", sb.toString());
    event = // 
    Log4jLogEvent.newBuilder().setLoggerName(// 
    "MyLogger").setLevel(// 
    Level.WARN).setMessage(msg).build();
    sb.setLength(0);
    converter.format(event, sb);
    assertEquals("Warning", sb.toString());
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Message(org.apache.logging.log4j.message.Message) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) LogEvent(org.apache.logging.log4j.core.LogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Test(org.junit.jupiter.api.Test)

Example 87 with Message

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

the class MarkerPatternConverterTest method testLookup.

@Test
public void testLookup() {
    final Message msg = new StructuredDataMessage("Test", "This is a test", "Audit");
    final Marker eventMarker = MarkerManager.getMarker("EVENT");
    final Marker auditMarker = MarkerManager.getMarker("AUDIT").setParents(eventMarker);
    final LogEvent event = Log4jLogEvent.newBuilder().setLoggerName("MyLogger").setMarker(auditMarker).setLevel(Level.DEBUG).setMessage(msg).build();
    final StringBuilder sb = new StringBuilder();
    final MarkerPatternConverter converter = MarkerPatternConverter.newInstance(null);
    converter.format(event, sb);
    assertEquals(auditMarker.toString(), sb.toString());
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Message(org.apache.logging.log4j.message.Message) StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) LogEvent(org.apache.logging.log4j.core.LogEvent) Marker(org.apache.logging.log4j.Marker) Test(org.junit.jupiter.api.Test)

Example 88 with Message

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

the class MarkerSimpleNamePatternConverterTest method testLookup.

@Test
public void testLookup() {
    final Message msg = new StructuredDataMessage("Test", "This is a test", "Audit");
    final Marker eventMarker = MarkerManager.getMarker("EVENT");
    final Marker auditMarker = MarkerManager.getMarker("AUDIT").setParents(eventMarker);
    final LogEvent event = Log4jLogEvent.newBuilder().setLoggerName("MyLogger").setMarker(auditMarker).setLevel(Level.DEBUG).setMessage(msg).build();
    final StringBuilder sb = new StringBuilder();
    final MarkerSimpleNamePatternConverter converter = MarkerSimpleNamePatternConverter.newInstance(null);
    converter.format(event, sb);
    assertEquals(auditMarker.getName(), sb.toString());
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Message(org.apache.logging.log4j.message.Message) StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) LogEvent(org.apache.logging.log4j.core.LogEvent) Marker(org.apache.logging.log4j.Marker) Test(org.junit.jupiter.api.Test)

Example 89 with Message

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

the class MaxLengthConverterTest method testOverMaxLength21WithEllipsis.

@Test
public void testOverMaxLength21WithEllipsis() {
    final Message message = new SimpleMessage("012345678901234567890123456789");
    final LogEvent event = Log4jLogEvent.newBuilder().setLoggerName("MyLogger").setLevel(Level.DEBUG).setMessage(message).build();
    final StringBuilder sb = new StringBuilder();
    MaxLengthConverter.newInstance(null, new String[] { "%m", "21" }).format(event, sb);
    assertEquals("012345678901234567890...", sb.toString());
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Message(org.apache.logging.log4j.message.Message) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) LogEvent(org.apache.logging.log4j.core.LogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Test(org.junit.jupiter.api.Test)

Example 90 with Message

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

the class MaxLengthConverterTest method testUnderMaxLength.

@Test
public void testUnderMaxLength() {
    final Message message = new SimpleMessage("0123456789");
    final LogEvent event = Log4jLogEvent.newBuilder().setLoggerName("MyLogger").setLevel(Level.DEBUG).setMessage(message).build();
    final StringBuilder sb = new StringBuilder();
    converter.format(event, sb);
    assertEquals("0123456789", sb.toString());
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Message(org.apache.logging.log4j.message.Message) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) LogEvent(org.apache.logging.log4j.core.LogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Test(org.junit.jupiter.api.Test)

Aggregations

Message (org.apache.logging.log4j.message.Message)128 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)88 LogEvent (org.apache.logging.log4j.core.LogEvent)55 Test (org.junit.jupiter.api.Test)50 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)46 Marker (org.apache.logging.log4j.Marker)26 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)26 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)24 Level (org.apache.logging.log4j.Level)23 Test (org.junit.Test)22 StringMapMessage (org.apache.logging.log4j.message.StringMapMessage)19 StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)18 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)17 MapMessage (org.apache.logging.log4j.message.MapMessage)15 StringMap (org.apache.logging.log4j.util.StringMap)15 DummyNanoClock (org.apache.logging.log4j.core.time.internal.DummyNanoClock)9 EntryMessage (org.apache.logging.log4j.message.EntryMessage)9 Map (java.util.Map)8 StringFormattedMessage (org.apache.logging.log4j.message.StringFormattedMessage)8 IOException (java.io.IOException)7