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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations