Search in sources :

Example 11 with LogMessage

use of io.cdap.cdap.logging.appender.LogMessage in project cdap by caskdata.

the class LoggingEventSerializerTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    Map<String, String> mdcMap = Maps.newHashMap();
    mdcMap.put("mdc1", "mdc-val1");
    mdcMap.put("mdc2", null);
    mdcMap.put(null, null);
    Map<String, String> contextMap = Maps.newHashMap();
    contextMap.put("p1", "ctx-val1");
    contextMap.put("p2", null);
    contextMap.put(null, null);
    LoggingEventSerializer serializer = new LoggingEventSerializer();
    ch.qos.logback.classic.spi.LoggingEvent iLoggingEvent = new ch.qos.logback.classic.spi.LoggingEvent();
    iLoggingEvent.setThreadName("threadName1");
    iLoggingEvent.setLevel(Level.INFO);
    iLoggingEvent.setMessage("Log message1");
    iLoggingEvent.setArgumentArray(new Object[] { null, "arg2", "100", null });
    iLoggingEvent.setLoggerName("loggerName1");
    iLoggingEvent.setLoggerContextRemoteView(new LoggerContextVO("logger_context1", contextMap, 12345634234L));
    Exception e1 = new Exception(null, null);
    Exception e2 = new Exception("Test Exception2", e1);
    iLoggingEvent.setThrowableProxy(new ThrowableProxy(e2));
    iLoggingEvent.prepareForDeferredProcessing();
    ((ThrowableProxy) iLoggingEvent.getThrowableProxy()).calculatePackagingData();
    iLoggingEvent.setCallerData(new StackTraceElement[] { new StackTraceElement("com.Class1", "methodName1", "fileName1", 10), null, new StackTraceElement("com.Class2", "methodName2", "fileName2", 20), new StackTraceElement("com.Class3", "methodName3", null, 30), null });
    iLoggingEvent.setMarker(null);
    iLoggingEvent.getMDCPropertyMap().putAll(mdcMap);
    iLoggingEvent.setTimeStamp(1234567890L);
    // Serialize
    ILoggingEvent event = new LogMessage(iLoggingEvent, LoggingContextAccessor.getLoggingContext());
    byte[] serializedBytes = serializer.toBytes(event);
    // De-serialize
    ILoggingEvent actualEvent = serializer.fromBytes(ByteBuffer.wrap(serializedBytes));
    System.out.println(actualEvent);
    assertLoggingEventEquals(iLoggingEvent, actualEvent);
}
Also used : IThrowableProxy(ch.qos.logback.classic.spi.IThrowableProxy) ThrowableProxy(ch.qos.logback.classic.spi.ThrowableProxy) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) IOException(java.io.IOException) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LogMessage(io.cdap.cdap.logging.appender.LogMessage) LoggerContextVO(ch.qos.logback.classic.spi.LoggerContextVO) Test(org.junit.Test)

Example 12 with LogMessage

use of io.cdap.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(io.cdap.cdap.logging.appender.LogMessage) LoggerContextVO(ch.qos.logback.classic.spi.LoggerContextVO) Test(org.junit.Test)

Example 13 with LogMessage

use of io.cdap.cdap.logging.appender.LogMessage in project cdap by caskdata.

the class LogsServiceMainTest method createLoggingEvent.

private ILoggingEvent createLoggingEvent(Level level, String message, long timestamp, LoggingContext loggingContext) {
    LoggingEvent event = new LoggingEvent();
    event.setLevel(level);
    event.setLoggerName("test.logger");
    event.setMessage(message);
    event.setTimeStamp(timestamp);
    return new LogMessage(event, loggingContext);
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) LogMessage(io.cdap.cdap.logging.appender.LogMessage)

Example 14 with LogMessage

use of io.cdap.cdap.logging.appender.LogMessage in project cdap by caskdata.

the class LoggingEventSerializerTest method testNullSerialization.

@Test
public void testNullSerialization() 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(null, (ch.qos.logback.classic.Logger) logger, null, null, null, null);
    iLoggingEvent.setThreadName(null);
    iLoggingEvent.setLevel(null);
    iLoggingEvent.setMessage(null);
    iLoggingEvent.setArgumentArray(null);
    iLoggingEvent.setLoggerName(null);
    iLoggingEvent.setLoggerContextRemoteView(null);
    iLoggingEvent.setThrowableProxy(null);
    iLoggingEvent.setCallerData(null);
    iLoggingEvent.setMarker(null);
    iLoggingEvent.setMDCPropertyMap(null);
    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));
    iLoggingEvent.setLevel(Level.ERROR);
    assertLoggingEventEquals(iLoggingEvent, actualEvent);
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LogMessage(io.cdap.cdap.logging.appender.LogMessage) Logger(org.slf4j.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Example 15 with LogMessage

use of io.cdap.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(io.cdap.cdap.logging.appender.LogMessage) Logger(org.slf4j.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Aggregations

ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)15 LogMessage (io.cdap.cdap.logging.appender.LogMessage)15 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)6 Test (org.junit.Test)6 Logger (org.slf4j.Logger)4 LoggingEventSerializer (io.cdap.cdap.logging.serialize.LoggingEventSerializer)3 LoggerContextVO (ch.qos.logback.classic.spi.LoggerContextVO)2 IOException (java.io.IOException)2 KafkaPublisher (org.apache.twill.kafka.client.KafkaPublisher)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 IThrowableProxy (ch.qos.logback.classic.spi.IThrowableProxy)1 ThrowableProxy (ch.qos.logback.classic.spi.ThrowableProxy)1 HttpExceptionHandler (io.cdap.cdap.common.HttpExceptionHandler)1 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)1 LoggingContext (io.cdap.cdap.common.logging.LoggingContext)1 RemoteLogAppender (io.cdap.cdap.logging.appender.remote.RemoteLogAppender)1 WorkerLoggingContext (io.cdap.cdap.logging.context.WorkerLoggingContext)1 ConcurrentLogBufferWriter (io.cdap.cdap.logging.logbuffer.ConcurrentLogBufferWriter)1 MockAppender (io.cdap.cdap.logging.pipeline.MockAppender)1 LogBufferProcessorPipeline (io.cdap.cdap.logging.pipeline.logbuffer.LogBufferProcessorPipeline)1