use of io.cdap.cdap.logging.appender.LogMessage in project cdap by caskdata.
the class LogBufferWriterTest method createLoggingEvent.
private ILoggingEvent createLoggingEvent(String loggerName, Level level, String message, long timestamp, LoggingContext loggingContext) {
LoggingEvent event = new LoggingEvent();
event.setLevel(level);
event.setLoggerName(loggerName);
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 LogBufferCleanerTest method createLoggingEvent.
private ILoggingEvent createLoggingEvent(String loggerName, Level level, String message, long timestamp, LoggingContext loggingContext) {
LoggingEvent event = new LoggingEvent();
event.setLevel(level);
event.setLoggerName(loggerName);
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 ConcurrentLogBufferWriterTest method createLoggingEvent.
private ILoggingEvent createLoggingEvent(String loggerName, Level level, String message, long timestamp, LoggingContext loggingContext) {
LoggingEvent event = new LoggingEvent();
event.setLevel(level);
event.setLoggerName(loggerName);
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 LogBufferHandlerTest method testHandler.
@Test
public void testHandler() throws Exception {
CConfiguration cConf = CConfiguration.create();
String absolutePath = TMP_FOLDER.newFolder().getAbsolutePath();
cConf.set(Constants.LogBuffer.LOG_BUFFER_BASE_DIR, absolutePath);
cConf.setLong(Constants.LogBuffer.LOG_BUFFER_MAX_FILE_SIZE_BYTES, 100000);
LoggerContext loggerContext = LogPipelineTestUtil.createLoggerContext("WARN", ImmutableMap.of("test.logger", "INFO"), MockAppender.class.getName());
final MockAppender appender = LogPipelineTestUtil.getAppender(loggerContext.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME), "Test", MockAppender.class);
LogBufferProcessorPipeline pipeline = getLogPipeline(loggerContext);
pipeline.startAndWait();
ConcurrentLogBufferWriter writer = new ConcurrentLogBufferWriter(cConf, ImmutableList.of(pipeline), () -> {
});
NettyHttpService httpService = NettyHttpService.builder("RemoteAppenderTest").setHttpHandlers(new LogBufferHandler(writer)).setExceptionHandler(new HttpExceptionHandler()).build();
httpService.start();
RemoteLogAppender remoteLogAppender = getRemoteAppender(cConf, httpService);
remoteLogAppender.start();
List<ILoggingEvent> events = getLoggingEvents();
WorkerLoggingContext loggingContext = new WorkerLoggingContext("default", "app1", "worker1", "run1", "instance1");
for (int i = 0; i < 1000; i++) {
remoteLogAppender.append(new LogMessage(events.get(i % events.size()), loggingContext));
}
Tasks.waitFor(1000, () -> appender.getEvents().size(), 120, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
remoteLogAppender.stop();
httpService.stop();
pipeline.stopAndWait();
loggerContext.stop();
}
use of io.cdap.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);
}
Aggregations