Search in sources :

Example 1 with LogMessage

use of co.cask.cdap.logging.appender.LogMessage in project cdap by caskdata.

the class KafkaLogProcessorPipelineTest method publishLog.

private void publishLog(String topic, Iterable<ILoggingEvent> events, LoggingContext context) {
    KafkaPublisher.Preparer preparer = KAFKA_TESTER.getKafkaClient().getPublisher(KafkaPublisher.Ack.LEADER_RECEIVED, Compression.NONE).prepare(topic);
    LoggingEventSerializer serializer = new LoggingEventSerializer();
    for (ILoggingEvent event : events) {
        preparer.add(ByteBuffer.wrap(serializer.toBytes(new LogMessage(event, context))), context.getLogPartition());
    }
    preparer.send();
}
Also used : LogMessage(co.cask.cdap.logging.appender.LogMessage) LoggingEventSerializer(co.cask.cdap.logging.serialize.LoggingEventSerializer) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) KafkaPublisher(org.apache.twill.kafka.client.KafkaPublisher)

Example 2 with LogMessage

use of co.cask.cdap.logging.appender.LogMessage in project cdap by caskdata.

the class LoggingEventTest method testEmptySerialize.

@Test
public void testEmptySerialize() throws Exception {
    Logger logger = LoggerFactory.getLogger(LoggingEventTest.class);
    ch.qos.logback.classic.spi.LoggingEvent iLoggingEvent = new ch.qos.logback.classic.spi.LoggingEvent(getClass().getName(), (ch.qos.logback.classic.Logger) logger, Level.ERROR, null, null, null);
    LoggingEventSerializer serializer = new LoggingEventSerializer();
    byte[] encoded = serializer.toBytes(new LogMessage(iLoggingEvent, LoggingContextAccessor.getLoggingContext()));
    ILoggingEvent decodedEvent = serializer.fromBytes(ByteBuffer.wrap(encoded));
    LoggingEventSerializerTest.assertLoggingEventEquals(iLoggingEvent, decodedEvent);
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LogMessage(co.cask.cdap.logging.appender.LogMessage) Logger(org.slf4j.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Example 3 with LogMessage

use of co.cask.cdap.logging.appender.LogMessage in project cdap by caskdata.

the class LoggingEventSerializerTest method testEmptySerialization.

@Test
public void testEmptySerialization() throws Exception {
    Logger logger = LoggerFactory.getLogger(LoggingEventSerializerTest.class);
    LoggingEventSerializer serializer = new LoggingEventSerializer();
    ch.qos.logback.classic.spi.LoggingEvent iLoggingEvent = new ch.qos.logback.classic.spi.LoggingEvent(getClass().getName(), (ch.qos.logback.classic.Logger) logger, Level.ERROR, "message", null, null);
    iLoggingEvent.setThreadName("thread-1");
    iLoggingEvent.setTimeStamp(10000000L);
    // Serialize
    ILoggingEvent event = new LogMessage(iLoggingEvent, LoggingContextAccessor.getLoggingContext());
    byte[] serializedBytes = serializer.toBytes(event);
    // De-serialize
    ILoggingEvent actualEvent = serializer.fromBytes(ByteBuffer.wrap(serializedBytes));
    assertLoggingEventEquals(iLoggingEvent, actualEvent);
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LogMessage(co.cask.cdap.logging.appender.LogMessage) Logger(org.slf4j.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Example 4 with LogMessage

use of co.cask.cdap.logging.appender.LogMessage in project cdap by caskdata.

the class DistributedLogFrameworkTest method publishLog.

/**
 * Publishes multiple log events.
 */
private void publishLog(String topic, LoggingContext context, Iterable<ILoggingEvent> events) {
    KafkaPublisher.Preparer preparer = KAFKA_TESTER.getKafkaClient().getPublisher(KafkaPublisher.Ack.LEADER_RECEIVED, Compression.NONE).prepare(topic);
    LoggingEventSerializer serializer = new LoggingEventSerializer();
    for (ILoggingEvent event : events) {
        preparer.add(ByteBuffer.wrap(serializer.toBytes(new LogMessage(event, context))), context.getLogPartition());
    }
    preparer.send();
}
Also used : LogMessage(co.cask.cdap.logging.appender.LogMessage) LoggingEventSerializer(co.cask.cdap.logging.serialize.LoggingEventSerializer) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) KafkaPublisher(org.apache.twill.kafka.client.KafkaPublisher)

Example 5 with LogMessage

use of co.cask.cdap.logging.appender.LogMessage in project cdap by caskdata.

the class LoggingEventTest method testSerialize.

@Test
public void testSerialize() throws Exception {
    Logger logger = LoggerFactory.getLogger(LoggingEventTest.class);
    ch.qos.logback.classic.spi.LoggingEvent iLoggingEvent = new ch.qos.logback.classic.spi.LoggingEvent(getClass().getName(), (ch.qos.logback.classic.Logger) logger, Level.ERROR, "Log message1", null, new Object[] { "arg1", "arg2", "100" });
    iLoggingEvent.setLoggerName("loggerName1");
    iLoggingEvent.setThreadName("threadName1");
    iLoggingEvent.setTimeStamp(1234567890L);
    iLoggingEvent.setLoggerContextRemoteView(new LoggerContextVO("loggerContextRemoteView", ImmutableMap.of("key1", "value1", "key2", "value2"), 100000L));
    Map<String, String> mdcMap = Maps.newHashMap(ImmutableMap.of("mdck1", "mdcv1", "mdck2", "mdck2"));
    iLoggingEvent.setMDCPropertyMap(mdcMap);
    LoggingEventSerializer serializer = new LoggingEventSerializer();
    byte[] encoded = serializer.toBytes(new LogMessage(iLoggingEvent, LoggingContextAccessor.getLoggingContext()));
    ILoggingEvent decodedEvent = serializer.fromBytes(ByteBuffer.wrap(encoded));
    LoggingEventSerializerTest.assertLoggingEventEquals(iLoggingEvent, decodedEvent);
}
Also used : Logger(org.slf4j.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LogMessage(co.cask.cdap.logging.appender.LogMessage) LoggerContextVO(ch.qos.logback.classic.spi.LoggerContextVO) Test(org.junit.Test)

Aggregations

ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)7 LogMessage (co.cask.cdap.logging.appender.LogMessage)7 Test (org.junit.Test)5 Logger (org.slf4j.Logger)4 LoggerContextVO (ch.qos.logback.classic.spi.LoggerContextVO)2 LoggingEventSerializer (co.cask.cdap.logging.serialize.LoggingEventSerializer)2 KafkaPublisher (org.apache.twill.kafka.client.KafkaPublisher)2 IThrowableProxy (ch.qos.logback.classic.spi.IThrowableProxy)1 ThrowableProxy (ch.qos.logback.classic.spi.ThrowableProxy)1 IOException (java.io.IOException)1