Search in sources :

Example 11 with LoggingEvent

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

the class CDAPLogAppenderTest method testCDAPLogAppender.

@Test
public void testCDAPLogAppender() throws Exception {
    int syncInterval = 1024 * 1024;
    CDAPLogAppender cdapLogAppender = new CDAPLogAppender();
    cdapLogAppender.setSyncIntervalBytes(syncInterval);
    cdapLogAppender.setMaxFileLifetimeMs(TimeUnit.DAYS.toMillis(1));
    cdapLogAppender.setMaxFileSizeInBytes(104857600);
    cdapLogAppender.setDirPermissions("700");
    cdapLogAppender.setFilePermissions("600");
    cdapLogAppender.setFileRetentionDurationDays(1);
    cdapLogAppender.setLogCleanupIntervalMins(10);
    cdapLogAppender.setFileCleanupTransactionTimeout(30);
    AppenderContext context = new LocalAppenderContext(injector.getInstance(DatasetFramework.class), injector.getInstance(TransactionSystemClient.class), injector.getInstance(LocationFactory.class), new NoOpMetricsCollectionService());
    context.start();
    cdapLogAppender.setContext(context);
    cdapLogAppender.start();
    FileMetaDataReader fileMetaDataReader = injector.getInstance(FileMetaDataReader.class);
    LoggingEvent event = new LoggingEvent("co.cask.Test", (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME), Level.ERROR, "test message", null, null);
    Map<String, String> properties = new HashMap<>();
    properties.put(NamespaceLoggingContext.TAG_NAMESPACE_ID, "default");
    properties.put(ApplicationLoggingContext.TAG_APPLICATION_ID, "testApp");
    properties.put(FlowletLoggingContext.TAG_FLOW_ID, "testFlow");
    properties.put(FlowletLoggingContext.TAG_FLOWLET_ID, "testFlowlet");
    event.setMDCPropertyMap(properties);
    cdapLogAppender.doAppend(event);
    cdapLogAppender.stop();
    context.stop();
    try {
        List<LogLocation> files = fileMetaDataReader.listFiles(cdapLogAppender.getLoggingPath(properties), 0, Long.MAX_VALUE);
        Assert.assertEquals(1, files.size());
        LogLocation logLocation = files.get(0);
        Assert.assertEquals(LogLocation.VERSION_1, logLocation.getFrameworkVersion());
        Assert.assertTrue(logLocation.getLocation().exists());
        CloseableIterator<LogEvent> logEventCloseableIterator = logLocation.readLog(Filter.EMPTY_FILTER, 0, Long.MAX_VALUE, Integer.MAX_VALUE);
        int logCount = 0;
        while (logEventCloseableIterator.hasNext()) {
            logCount++;
            LogEvent logEvent = logEventCloseableIterator.next();
            Assert.assertEquals(event.getMessage(), logEvent.getLoggingEvent().getMessage());
        }
        logEventCloseableIterator.close();
        Assert.assertEquals(1, logCount);
        // checking permission
        String expectedPermissions = "rw-------";
        for (LogLocation file : files) {
            Location location = file.getLocation();
            Assert.assertEquals(expectedPermissions, location.getPermissions());
        }
    } catch (Exception e) {
        Assert.fail();
    }
}
Also used : HashMap(java.util.HashMap) LogEvent(co.cask.cdap.logging.read.LogEvent) NoOpMetricsCollectionService(co.cask.cdap.common.metrics.NoOpMetricsCollectionService) IOException(java.io.IOException) LocationFactory(org.apache.twill.filesystem.LocationFactory) DatasetFramework(co.cask.cdap.data2.dataset2.DatasetFramework) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) TransactionSystemClient(org.apache.tephra.TransactionSystemClient) LocalAppenderContext(co.cask.cdap.logging.framework.LocalAppenderContext) LogLocation(co.cask.cdap.logging.write.LogLocation) LocalAppenderContext(co.cask.cdap.logging.framework.LocalAppenderContext) AppenderContext(co.cask.cdap.api.logging.AppenderContext) FileMetaDataReader(co.cask.cdap.logging.meta.FileMetaDataReader) Location(org.apache.twill.filesystem.Location) LogLocation(co.cask.cdap.logging.write.LogLocation) Test(org.junit.Test)

Example 12 with LoggingEvent

use of ch.qos.logback.classic.spi.LoggingEvent 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 13 with LoggingEvent

use of ch.qos.logback.classic.spi.LoggingEvent in project cdap-ingest by caskdata.

the class FileTailerMetricsProcessor method writeMetrics.

/**
   * Writes metric to metrics file.
   *
   * @param logger the logger
   * @param appender the file appender
   * @param currentDate the date of creating this metric
   */
private void writeMetrics(ch.qos.logback.classic.Logger logger, RollingFileAppender appender, String currentDate) {
    LOG.debug("Start writing metric with date {} to file ..", currentDate);
    String metric = new StringBuilder(currentDate).append(",").append(flowName).append(",").append(fileName).append(",").append(totalEventsReadPerFile.get()).append(",").append(totalEventsIngestedPerFile.get()).append(",").append(minEventSizePerFile.get()).append(",").append(calculateAverage(totalEventSizePerFile.get(), eventsPerFile.get())).append(",").append(maxEventSizePerFile.get()).append(",").append(minWriteLatencyPerStream.get()).append(",").append(calculateAverage(totalWriteLatencyPerStream.get(), writesPerStream.get())).append(",").append(maxWriteLatencyPerStream.get()).toString();
    appender.doAppend(new LoggingEvent(loggerClass, logger, null, metric, null, null));
    LOG.debug("Successfully wrote metric with date: {}", currentDate);
}
Also used : LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent)

Example 14 with LoggingEvent

use of ch.qos.logback.classic.spi.LoggingEvent in project dropwizard by dropwizard.

the class DropwizardSlf4jRequestLog method write.

@Override
public void write(String entry) throws IOException {
    final LoggingEvent event = new LoggingEvent();
    event.setLevel(Level.INFO);
    event.setLoggerName("http.request");
    event.setMessage(entry);
    event.setTimeStamp(System.currentTimeMillis());
    appenders.appendLoopOnAppenders(event);
}
Also used : LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 15 with LoggingEvent

use of ch.qos.logback.classic.spi.LoggingEvent in project spring-boot by spring-projects.

the class ColorConverterTests method setup.

@Before
public void setup() {
    this.converter = new ColorConverter();
    this.event = new LoggingEvent();
}
Also used : LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) Before(org.junit.Before)

Aggregations

LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)20 Test (org.junit.Test)8 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)5 DatasetFramework (co.cask.cdap.data2.dataset2.DatasetFramework)4 Timestamp (com.google.cloud.Timestamp)4 LogEntry (com.google.cloud.logging.LogEntry)4 TransactionSystemClient (org.apache.tephra.TransactionSystemClient)4 LocationFactory (org.apache.twill.filesystem.LocationFactory)4 AppenderContext (co.cask.cdap.api.logging.AppenderContext)3 NoOpMetricsCollectionService (co.cask.cdap.common.metrics.NoOpMetricsCollectionService)3 LocalAppenderContext (co.cask.cdap.logging.framework.LocalAppenderContext)3 FileMetaDataReader (co.cask.cdap.logging.meta.FileMetaDataReader)3 LogEvent (co.cask.cdap.logging.read.LogEvent)3 LogLocation (co.cask.cdap.logging.write.LogLocation)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 LogOffset (co.cask.cdap.logging.read.LogOffset)2 Location (org.apache.twill.filesystem.Location)2 ThresholdFilter (ch.qos.logback.classic.filter.ThresholdFilter)1