Search in sources :

Example 6 with LogMessage

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);
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) LogMessage(io.cdap.cdap.logging.appender.LogMessage)

Example 7 with LogMessage

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);
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) LogMessage(io.cdap.cdap.logging.appender.LogMessage)

Example 8 with LogMessage

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);
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) LogMessage(io.cdap.cdap.logging.appender.LogMessage)

Example 9 with LogMessage

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();
}
Also used : WorkerLoggingContext(io.cdap.cdap.logging.context.WorkerLoggingContext) RemoteLogAppender(io.cdap.cdap.logging.appender.remote.RemoteLogAppender) HttpExceptionHandler(io.cdap.cdap.common.HttpExceptionHandler) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) LoggerContext(ch.qos.logback.classic.LoggerContext) MockAppender(io.cdap.cdap.logging.pipeline.MockAppender) LogMessage(io.cdap.cdap.logging.appender.LogMessage) LogBufferProcessorPipeline(io.cdap.cdap.logging.pipeline.logbuffer.LogBufferProcessorPipeline) NettyHttpService(io.cdap.http.NettyHttpService) ConcurrentLogBufferWriter(io.cdap.cdap.logging.logbuffer.ConcurrentLogBufferWriter) Test(org.junit.Test)

Example 10 with LogMessage

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