Search in sources :

Example 6 with StructuredDataMessage

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

the class FlumeEmbeddedAppenderTest method testHeaderAddedByInterceptor.

/* Flume 1.4.0 does not support interceptors on the embedded agent
    @Test      */
public void testHeaderAddedByInterceptor() {
    final StructuredDataMessage msg = new StructuredDataMessage("Test", "Test Log4j", "Test");
    EventLogger.logEvent(msg);
    final Event event = primary.poll();
    Assert.assertNotNull("Event should not be null", event);
    final String environmentHeader = event.getHeaders().get("environment");
    Assert.assertEquals("local", environmentHeader);
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Event(org.apache.flume.Event) AvroFlumeEvent(org.apache.flume.source.avro.AvroFlumeEvent)

Example 7 with StructuredDataMessage

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

the class FlumeEmbeddedAppenderTest method testPerformance.

/* @Test */
public void testPerformance() throws Exception {
    final long start = System.currentTimeMillis();
    final int count = 10000;
    for (int i = 0; i < count; ++i) {
        final StructuredDataMessage msg = new StructuredDataMessage("Test", "Test Primary " + i, "Test");
        msg.put("counter", Integer.toString(i));
        EventLogger.logEvent(msg);
    }
    final long elapsed = System.currentTimeMillis() - start;
    System.out.println("Time to log " + count + " events " + elapsed + "ms");
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage)

Example 8 with StructuredDataMessage

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

the class LoggerTest method structuredData.

@Test
public void structuredData() {
    ThreadContext.put("loginId", "JohnDoe");
    ThreadContext.put("ipAddress", "192.168.0.120");
    ThreadContext.put("locale", Locale.US.getDisplayName());
    final StructuredDataMessage msg = new StructuredDataMessage("Audit@18060", "Transfer Complete", "Transfer");
    msg.put("ToAccount", "123456");
    msg.put("FromAccount", "123457");
    msg.put("Amount", "200.00");
    logger.info(MarkerManager.getMarker("EVENT"), msg);
    ThreadContext.clearMap();
    final List<LogEvent> events = app.getEvents();
    assertEventCount(events, 1);
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Test(org.junit.Test)

Example 9 with StructuredDataMessage

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

the class SyslogAppenderTestBase method sendInfoStructuredMessage.

protected void sendInfoStructuredMessage() {
    ThreadContext.put("loginId", "JohnDoe");
    ThreadContext.put("ipAddress", "192.168.0.120");
    ThreadContext.put("locale", Locale.US.getDisplayName());
    final StructuredDataMessage msg = new StructuredDataMessage("Transfer@18060", "Transfer Complete", "Audit");
    msg.put("ToAccount", "123456");
    msg.put("FromAccount", "123457");
    msg.put("Amount", "200.00");
    // the msg.toString() doesn't contain the parameters of the ThreadContext, so we must use the line1 string
    final String str = msg.asString(null, null);
    sentMessages.add(str);
    root.info(MarkerManager.getMarker("EVENT"), msg);
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage)

Example 10 with StructuredDataMessage

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

the class MapRewritePolicyTest method setupClass.

@BeforeClass
public static void setupClass() {
    map.put("test1", "one");
    map.put("test2", "two");
    logEvent0 = //
    Log4jLogEvent.newBuilder().setLoggerName(//
    "test").setContextMap(//
    map).setLoggerFqcn(//
    "MapRewritePolicyTest.setupClass()").setLevel(//
    Level.ERROR).setMessage(//
    new SimpleMessage("Test")).setThrown(//
    new RuntimeException("test")).setThreadName("none").setSource(new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 28)).setTimeMillis(2).build();
    logEvent1 = //
    ((Log4jLogEvent) logEvent0).asBuilder().setMessage(//
    new MapMessage(map)).setSource(//
    new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 29)).build();
    final ThreadContextStack stack = new MutableThreadContextStack(new ArrayList<>(map.values()));
    logEvent2 = //
    ((Log4jLogEvent) logEvent0).asBuilder().setContextStack(//
    stack).setMarker(//
    MarkerManager.getMarker("test")).setLevel(//
    Level.TRACE).setMessage(//
    new StructuredDataMessage("test", "Nothing", "test", map)).setTimeMillis(//
    20000000).setSource(//
    new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 30)).build();
    logEvent3 = //
    ((Log4jLogEvent) logEvent0).asBuilder().setContextStack(//
    stack).setLevel(//
    Level.ALL).setMessage(//
    new MapMessage(map)).setTimeMillis(//
    Long.MAX_VALUE).setSource(//
    new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 31)).build();
    rewrite = new KeyValuePair[] { new KeyValuePair("test2", "2"), new KeyValuePair("test3", "three") };
}
Also used : MutableThreadContextStack(org.apache.logging.log4j.spi.MutableThreadContextStack) ThreadContextStack(org.apache.logging.log4j.spi.ThreadContextStack) StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) KeyValuePair(org.apache.logging.log4j.core.util.KeyValuePair) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) MapMessage(org.apache.logging.log4j.message.MapMessage) MutableThreadContextStack(org.apache.logging.log4j.spi.MutableThreadContextStack) BeforeClass(org.junit.BeforeClass)

Aggregations

StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)40 Test (org.junit.Test)32 Event (org.apache.flume.Event)12 AvroFlumeEvent (org.apache.flume.source.avro.AvroFlumeEvent)11 LogEvent (org.apache.logging.log4j.core.LogEvent)11 File (java.io.File)6 Message (org.apache.logging.log4j.message.Message)6 EventLogger (org.apache.logging.log4j.EventLogger)5 Logger (org.apache.logging.log4j.Logger)4 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)4 StatusLogger (org.apache.logging.log4j.status.StatusLogger)4 Appender (org.apache.logging.log4j.core.Appender)3 ListAppender (org.apache.logging.log4j.test.appender.ListAppender)3 Map (java.util.Map)2 Marker (org.apache.logging.log4j.Marker)2 KeyValuePair (org.apache.logging.log4j.core.util.KeyValuePair)2 MapMessage (org.apache.logging.log4j.message.MapMessage)2 HashMap (java.util.HashMap)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1