Search in sources :

Example 46 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project cdap by caskdata.

the class DistributedLogFrameworkTest method createLoggingEvent.

/**
   * Creates an {@link ILoggingEvent}.
   */
private ILoggingEvent createLoggingEvent(String loggerName, Level level, String message, long timestamp) {
    LoggingEvent event = new LoggingEvent();
    event.setLevel(level);
    event.setLoggerName(loggerName);
    event.setMessage(message);
    event.setTimeStamp(timestamp);
    return event;
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent)

Example 47 with ILoggingEvent

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

Example 48 with ILoggingEvent

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

Example 49 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project cdap by caskdata.

the class LogPipelineConfigurator method buildInterpreter.

@Override
protected void buildInterpreter() {
    super.buildInterpreter();
    RuleStore ruleStore = interpreter.getRuleStore();
    ruleStore.addRule(new Pattern("configuration/contextName"), new ContextConfigAction(cConf));
    ruleStore.addRule(new Pattern("configuration/appender"), new WrapAppenderAction<ILoggingEvent>());
}
Also used : Pattern(ch.qos.logback.core.joran.spi.Pattern) RuleStore(ch.qos.logback.core.joran.spi.RuleStore) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 50 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project cdap by caskdata.

the class LogLocation method readToEndSyncPosition.

/**
   *  Read current block in Avro file from current block sync marker to next block sync marker
   */
private List<LogEvent> readToEndSyncPosition(DataFileReader<GenericRecord> dataFileReader, Filter logFilter, long fromTimeMs, long endSyncPosition) throws IOException {
    List<LogEvent> logSegment = new ArrayList<>();
    long currentSyncPosition = dataFileReader.previousSync();
    // or read until endSyncPosition has been reached
    while (dataFileReader.hasNext() && (endSyncPosition == -1 || (currentSyncPosition < endSyncPosition))) {
        ILoggingEvent loggingEvent = new LoggingEvent(dataFileReader.next());
        loggingEvent.prepareForDeferredProcessing();
        // Stop when reached fromTimeMs
        if (loggingEvent.getTimeStamp() > fromTimeMs) {
            break;
        }
        if (logFilter.match(loggingEvent)) {
            logSegment.add(new LogEvent(loggingEvent, new LogOffset(LogOffset.INVALID_KAFKA_OFFSET, loggingEvent.getTimeStamp())));
        }
        currentSyncPosition = dataFileReader.previousSync();
    }
    return logSegment;
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggingEvent(co.cask.cdap.logging.serialize.LoggingEvent) LogEvent(co.cask.cdap.logging.read.LogEvent) LogOffset(co.cask.cdap.logging.read.LogOffset) ArrayList(java.util.ArrayList) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Aggregations

ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)106 Test (org.junit.Test)47 LoggerContext (ch.qos.logback.classic.LoggerContext)37 Logger (ch.qos.logback.classic.Logger)34 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)19 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)18 FileAppender (ch.qos.logback.core.FileAppender)17 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)17 File (java.io.File)15 Appender (ch.qos.logback.core.Appender)12 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)12 AsyncAppender (ch.qos.logback.classic.AsyncAppender)10 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)10 NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)10 ArrayList (java.util.ArrayList)9 Logger (org.slf4j.Logger)9 LogMessage (co.cask.cdap.logging.appender.LogMessage)7 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)6 IOException (java.io.IOException)6 SlingRollingFileAppender (org.apache.sling.commons.log.logback.internal.util.SlingRollingFileAppender)6