loggingEventEnhancerClassNames = new HashSet<>();
@@ -214,6 +218,18 @@ public void setRedirectToStdout(boolean flag) {
redirectToStdout = flag;
}
+ /**
+ * Sets the flag indicating if a batch's valid entries should be written even if some other entry
+ * failed due to an error.
+ *
+ * Default to {@code true}.
+ *
+ * @param flag the partialSuccess flag.
+ */
+ public void setPartialSuccess(boolean flag) {
+ partialSuccess = flag;
+ }
+
/** Add extra labels using classes that implement {@link LoggingEnhancer}. */
public void addEnhancer(String enhancerClassName) {
this.enhancerClassNames.add(enhancerClassName);
@@ -298,7 +314,9 @@ public synchronized void start() {
defaultWriteOptions =
new WriteOption[] {
- WriteOption.logName(getLogName()), WriteOption.resource(monitoredResource)
+ WriteOption.logName(getLogName()),
+ WriteOption.resource(monitoredResource),
+ WriteOption.partialSuccess(partialSuccess)
};
Level flushLevel = getFlushLevel();
if (flushLevel != Level.OFF) {
diff --git a/src/test/java/com/google/cloud/logging/logback/LoggingAppenderTest.java b/src/test/java/com/google/cloud/logging/logback/LoggingAppenderTest.java
index f1bdbebf4..ac97cbc3f 100644
--- a/src/test/java/com/google/cloud/logging/logback/LoggingAppenderTest.java
+++ b/src/test/java/com/google/cloud/logging/logback/LoggingAppenderTest.java
@@ -160,7 +160,8 @@ public void setUp() {
new ImmutableMap.Builder()
.put("project_id", PROJECT_ID)
.build())
- .build())
+ .build()),
+ WriteOption.partialSuccess(true),
};
@Test
@@ -168,7 +169,10 @@ public void testFlushLevelConfigUpdatesLoggingFlushSeverity() {
logging.setFlushSeverity(Severity.WARNING);
Capture> capturedArgument = Capture.newInstance();
logging.write(
- capture(capturedArgument), anyObject(WriteOption.class), anyObject(WriteOption.class));
+ capture(capturedArgument),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class));
replay(logging);
Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(100000, 0);
LoggingEvent loggingEvent = createLoggingEvent(Level.WARN, timestamp.getSeconds());
@@ -194,7 +198,10 @@ public void testFilterLogsOnlyLogsAtOrAboveLogLevel() {
logging.setFlushSeverity(Severity.ERROR);
Capture> capturedArgument = Capture.newInstance();
logging.write(
- capture(capturedArgument), anyObject(WriteOption.class), anyObject(WriteOption.class));
+ capture(capturedArgument),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class));
expectLastCall().once();
replay(logging);
Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(100000, 0);
@@ -215,12 +222,16 @@ public void testFilterLogsOnlyLogsAtOrAboveLogLevel() {
}
@Test
- public void testDefaultWriteOptionsHasExpectedDefaults() {
+ public void testPartialSuccessOverrideHasExpectedValue() {
logging.setFlushSeverity(Severity.ERROR);
Capture logNameArg = Capture.newInstance();
Capture resourceArg = Capture.newInstance();
+ Capture partialSuccessArg = Capture.newInstance();
logging.write(
- EasyMock.>anyObject(), capture(logNameArg), capture(resourceArg));
+ EasyMock.>anyObject(),
+ capture(logNameArg),
+ capture(resourceArg),
+ capture(partialSuccessArg));
expectLastCall().once();
replay(logging);
loggingAppender.start();
@@ -231,6 +242,26 @@ public void testDefaultWriteOptionsHasExpectedDefaults() {
assertThat(logNameArg.getValue()).isEqualTo(defaultWriteOptions[0]);
// TODO(chingor): Fix this test to work on GCE and locally
// assertThat(resourceArg.getValue()).isEqualTo(defaultWriteOptions[1]);
+ assertThat(partialSuccessArg.getValue()).isEqualTo(defaultWriteOptions[2]);
+ }
+
+ @Test
+ public void testDefaultWriteOptionsHasExpectedDefaults() {
+ logging.setFlushSeverity(Severity.ERROR);
+ Capture partialSuccessArg = Capture.newInstance();
+ logging.write(
+ EasyMock.>anyObject(),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class),
+ capture(partialSuccessArg));
+ expectLastCall().once();
+ replay(logging);
+ loggingAppender.setPartialSuccess(false);
+ loggingAppender.start();
+ Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(100000, 0);
+ LoggingEvent loggingEvent = createLoggingEvent(Level.ERROR, timestamp.getSeconds());
+ loggingAppender.doAppend(loggingEvent);
+ assertThat(partialSuccessArg.getValue()).isEqualTo(WriteOption.partialSuccess(false));
}
@Test
@@ -238,7 +269,10 @@ public void testMdcValuesAreConvertedToLabels() {
logging.setFlushSeverity(Severity.ERROR);
Capture> capturedArgument = Capture.newInstance();
logging.write(
- capture(capturedArgument), anyObject(WriteOption.class), anyObject(WriteOption.class));
+ capture(capturedArgument),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class));
expectLastCall().once();
replay(logging);
Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(100000, 0);
@@ -294,7 +328,10 @@ public void testMdcValuesAreConvertedToLabelsWithPassingNullValues() {
logging.setFlushSeverity(Severity.ERROR);
Capture> capturedArgument = Capture.newInstance();
logging.write(
- capture(capturedArgument), anyObject(WriteOption.class), anyObject(WriteOption.class));
+ capture(capturedArgument),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class));
expectLastCall().once();
replay(logging);
Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(100000, 0);
@@ -317,7 +354,10 @@ public void testAddCustomLoggingEventEnhancers() {
logging.setFlushSeverity(Severity.ERROR);
Capture> capturedArgument = Capture.newInstance();
logging.write(
- capture(capturedArgument), anyObject(WriteOption.class), anyObject(WriteOption.class));
+ capture(capturedArgument),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class));
expectLastCall().once();
replay(logging);
Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(100000, 0);
@@ -338,7 +378,10 @@ public void testAddCustomLoggingEnhancer() {
logging.setFlushSeverity(Severity.ERROR);
Capture> capturedArgument = Capture.newInstance();
logging.write(
- capture(capturedArgument), anyObject(WriteOption.class), anyObject(WriteOption.class));
+ capture(capturedArgument),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class));
expectLastCall().once();
replay(logging);
loggingAppender.addEnhancer(CustomLoggingEnhancer.class.getName());
@@ -359,6 +402,7 @@ public void testFlush() {
logging.write(
EasyMock.>anyObject(),
anyObject(WriteOption.class),
+ anyObject(WriteOption.class),
anyObject(WriteOption.class));
expectLastCall().times(2);
logging.flush();
@@ -395,6 +439,7 @@ public void testAutoPopulationEnabled() {
logging.write(
EasyMock.>anyObject(),
anyObject(WriteOption.class),
+ anyObject(WriteOption.class),
anyObject(WriteOption.class));
expectLastCall().once();
replay(logging);
@@ -460,7 +505,10 @@ public void testFDiagnosticInfoAdded() {
Capture> capturedArgument = Capture.newInstance();
logging.setFlushSeverity(Severity.ERROR);
logging.write(
- capture(capturedArgument), anyObject(WriteOption.class), anyObject(WriteOption.class));
+ capture(capturedArgument),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class));
replay(logging);
LoggingEvent loggingEvent =
createLoggingEvent(Level.ERROR, Timestamp.ofTimeSecondsAndNanos(100000, 0).getSeconds());
@@ -502,7 +550,10 @@ public void testFDiagnosticInfoNotAdded() {
logging.setFlushSeverity(Severity.ERROR);
Capture> capturedArgument = Capture.newInstance();
logging.write(
- capture(capturedArgument), anyObject(WriteOption.class), anyObject(WriteOption.class));
+ capture(capturedArgument),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class),
+ anyObject(WriteOption.class));
replay(logging);
LoggingEvent loggingEvent =
createLoggingEvent(Level.WARN, Timestamp.ofTimeSecondsAndNanos(100000, 0).getSeconds());
diff --git a/versions.txt b/versions.txt
index 1eb668e7e..6b78553ef 100644
--- a/versions.txt
+++ b/versions.txt
@@ -1,4 +1,4 @@
# Format:
# module:released-version:current-version
-google-cloud-logging-logback:0.127.17-alpha:0.127.17-alpha
+google-cloud-logging-logback:0.128.0-alpha:0.128.0-alpha