Search in sources :

Example 1 with LoggingEvent

use of ch.qos.logback.classic.spi.LoggingEvent in project google-cloud-java by GoogleCloudPlatform.

the class LoggingAppenderTest method testDefaultWriteOptionsHasExpectedDefaults.

@Test
public void testDefaultWriteOptionsHasExpectedDefaults() {
    logging.setFlushSeverity(Severity.ERROR);
    Capture<WriteOption> logNameArg = Capture.newInstance();
    Capture<WriteOption> resourceArg = Capture.newInstance();
    logging.write((Iterable<LogEntry>) anyObject(), capture(logNameArg), capture(resourceArg));
    expectLastCall().once();
    replay(logging);
    loggingAppender.start();
    Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(100000, 0);
    LoggingEvent loggingEvent = createLoggingEvent(Level.ERROR, timestamp.getSeconds());
    loggingAppender.doAppend(loggingEvent);
    Assert.assertTrue(logNameArg.getValue().equals(defaultWriteOptions[0]));
    Assert.assertTrue(resourceArg.getValue().equals(defaultWriteOptions[1]));
}
Also used : LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) Timestamp(com.google.cloud.Timestamp) LogEntry(com.google.cloud.logging.LogEntry) WriteOption(com.google.cloud.logging.Logging.WriteOption) Test(org.junit.Test)

Example 2 with LoggingEvent

use of ch.qos.logback.classic.spi.LoggingEvent in project google-cloud-java by GoogleCloudPlatform.

the class LoggingAppenderTest method createLoggingEvent.

private LoggingEvent createLoggingEvent(Level level, long timestamp) {
    LoggingEvent loggingEvent = new LoggingEvent();
    loggingEvent.setMessage("this is a test");
    loggingEvent.setLevel(level);
    loggingEvent.setTimeStamp(timestamp);
    return loggingEvent;
}
Also used : LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent)

Example 3 with LoggingEvent

use of ch.qos.logback.classic.spi.LoggingEvent in project google-cloud-java by GoogleCloudPlatform.

the class LoggingAppenderTest method testFilterLogsOnlyLogsAtOrAboveLogLevel.

@Test
public void testFilterLogsOnlyLogsAtOrAboveLogLevel() {
    LogEntry logEntry = LogEntry.newBuilder(StringPayload.of("this is a test")).setTimestamp(100000L).setSeverity(Severity.ERROR).setLabels(new ImmutableMap.Builder<String, String>().put("levelName", "ERROR").put("levelValue", String.valueOf(40000L)).build()).build();
    logging.setFlushSeverity(Severity.ERROR);
    Capture<Iterable<LogEntry>> capturedArgument = Capture.newInstance();
    logging.write(capture(capturedArgument), (WriteOption) anyObject(), (WriteOption) anyObject());
    expectLastCall().once();
    replay(logging);
    Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(100000, 0);
    LoggingEvent loggingEvent1 = createLoggingEvent(Level.INFO, timestamp.getSeconds());
    ThresholdFilter thresholdFilter = new ThresholdFilter();
    thresholdFilter.setLevel("ERROR");
    thresholdFilter.start();
    loggingAppender.addFilter(thresholdFilter);
    loggingAppender.start();
    // info event does not get logged
    loggingAppender.doAppend(loggingEvent1);
    LoggingEvent loggingEvent2 = createLoggingEvent(Level.ERROR, timestamp.getSeconds());
    // error event gets logged
    loggingAppender.doAppend(loggingEvent2);
    verify(logging);
    Assert.assertTrue(capturedArgument.getValue().iterator().hasNext());
    Assert.assertTrue(logEntry.equals(capturedArgument.getValue().iterator().next()));
}
Also used : LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) ThresholdFilter(ch.qos.logback.classic.filter.ThresholdFilter) Timestamp(com.google.cloud.Timestamp) LogEntry(com.google.cloud.logging.LogEntry) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 4 with LoggingEvent

use of ch.qos.logback.classic.spi.LoggingEvent in project google-cloud-java by GoogleCloudPlatform.

the class LoggingAppenderTest method testEnhancersAddCorrectLabelsToLogEntries.

@Test
public void testEnhancersAddCorrectLabelsToLogEntries() {
    LogEntry logEntry = LogEntry.newBuilder(StringPayload.of("this is a test")).setTimestamp(100000L).setSeverity(Severity.WARNING).setLabels(new ImmutableMap.Builder<String, String>().put("levelName", "WARN").put("levelValue", String.valueOf(30000L)).put("test-label-1", "test-value-1").put("test-label-2", "test-value-2").build()).build();
    logging.setFlushSeverity(Severity.ERROR);
    Capture<Iterable<LogEntry>> capturedArgument = Capture.newInstance();
    logging.write(capture(capturedArgument), (WriteOption) anyObject(), (WriteOption) anyObject());
    expectLastCall().once();
    replay(logging);
    loggingAppender.addEnhancer("com.example.enhancers.TestLoggingEnhancer");
    loggingAppender.addEnhancer("com.example.enhancers.AnotherTestLoggingEnhancer");
    loggingAppender.start();
    Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(100000, 0);
    LoggingEvent loggingEvent = createLoggingEvent(Level.WARN, timestamp.getSeconds());
    loggingAppender.doAppend(loggingEvent);
    verify(logging);
    Assert.assertTrue(capturedArgument.getValue().iterator().hasNext());
    Assert.assertTrue(logEntry.equals(capturedArgument.getValue().iterator().next()));
}
Also used : LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) Timestamp(com.google.cloud.Timestamp) LogEntry(com.google.cloud.logging.LogEntry) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 5 with LoggingEvent

use of ch.qos.logback.classic.spi.LoggingEvent in project google-cloud-java by GoogleCloudPlatform.

the class LoggingAppenderTest method testFlushLevelConfigUpdatesLoggingFlushSeverity.

@Test
public void testFlushLevelConfigUpdatesLoggingFlushSeverity() {
    LogEntry logEntry = LogEntry.newBuilder(StringPayload.of("this is a test")).setTimestamp(100000L).setSeverity(Severity.WARNING).setLabels(new ImmutableMap.Builder<String, String>().put("levelName", "WARN").put("levelValue", String.valueOf(30000L)).build()).build();
    logging.setFlushSeverity(Severity.WARNING);
    Capture<Iterable<LogEntry>> capturedArgument = Capture.newInstance();
    logging.write(capture(capturedArgument), (WriteOption) anyObject(), (WriteOption) anyObject());
    replay(logging);
    Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(100000, 0);
    LoggingEvent loggingEvent = createLoggingEvent(Level.WARN, timestamp.getSeconds());
    // error is the default, updating to warn for test
    loggingAppender.setFlushLevel(Level.WARN);
    loggingAppender.start();
    loggingAppender.doAppend(loggingEvent);
    verify(logging);
    Assert.assertTrue(capturedArgument.getValue().iterator().hasNext());
    Assert.assertTrue(logEntry.equals(capturedArgument.getValue().iterator().next()));
}
Also used : LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) Timestamp(com.google.cloud.Timestamp) LogEntry(com.google.cloud.logging.LogEntry) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

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