Search in sources :

Example 1 with EventLogger

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

the class FlumePersistentAppenderTest method testSingle.

@Test
public void testSingle() throws IOException {
    final Logger logger = LogManager.getLogger("EventLogger");
    final Marker marker = MarkerManager.getMarker("EVENT");
    logger.info(marker, "This is a test message");
    final Event event = primary.poll();
    Assert.assertNotNull(event);
    final String body = getBody(event);
    Assert.assertTrue("Channel contained event, but not expected message. Received: " + body, body.endsWith("This is a test message"));
}
Also used : Event(org.apache.flume.Event) AvroFlumeEvent(org.apache.flume.source.avro.AvroFlumeEvent) Marker(org.apache.logging.log4j.Marker) EventLogger(org.apache.logging.log4j.EventLogger) Logger(org.apache.logging.log4j.Logger) StatusLogger(org.apache.logging.log4j.status.StatusLogger) Test(org.junit.Test)

Example 2 with EventLogger

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

the class FlumeAppenderTest method testStructured.

@Test
public void testStructured() throws IOException {
    final Agent[] agents = new Agent[] { Agent.createAgent("localhost", testPort) };
    final FlumeAppender avroAppender = FlumeAppender.createAppender(agents, null, null, "false", "Avro", null, "1000", "1000", "1", "1000", "avro", "false", null, null, null, "ReqCtx_", null, "true", "1", null, null, null, null);
    avroAppender.start();
    final Logger eventLogger = (Logger) LogManager.getLogger("EventLogger");
    Assert.assertNotNull(eventLogger);
    eventLogger.addAppender(avroAppender);
    eventLogger.setLevel(Level.ALL);
    final StructuredDataMessage msg = new StructuredDataMessage("Transfer", "Success", "Audit");
    msg.put("memo", "This is a memo");
    msg.put("acct", "12345");
    msg.put("amount", "100.00");
    ThreadContext.put("id", UUID.randomUUID().toString());
    ThreadContext.put("memo", null);
    ThreadContext.put("test", "123");
    EventLogger.logEvent(msg);
    final Transaction transaction = channel.getTransaction();
    transaction.begin();
    final Event event = channel.take();
    Assert.assertNotNull(event);
    Assert.assertTrue("Channel contained event, but not expected message", getBody(event).endsWith("Success"));
    transaction.commit();
    transaction.close();
    eventSource.stop();
    eventLogger.removeAppender(avroAppender);
    avroAppender.stop();
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Transaction(org.apache.flume.Transaction) Event(org.apache.flume.Event) Logger(org.apache.logging.log4j.core.Logger) EventLogger(org.apache.logging.log4j.EventLogger) StatusLogger(org.apache.logging.log4j.status.StatusLogger) Test(org.junit.Test)

Aggregations

Event (org.apache.flume.Event)2 EventLogger (org.apache.logging.log4j.EventLogger)2 StatusLogger (org.apache.logging.log4j.status.StatusLogger)2 Test (org.junit.Test)2 Transaction (org.apache.flume.Transaction)1 AvroFlumeEvent (org.apache.flume.source.avro.AvroFlumeEvent)1 Logger (org.apache.logging.log4j.Logger)1 Marker (org.apache.logging.log4j.Marker)1 Logger (org.apache.logging.log4j.core.Logger)1 StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)1