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