Skip to content

Commit 34a9539

Browse files
authored
Fix: Fix Appender default flushlevel to be consistent with java-logging (#1441)
* Fix: Fix Appender default flushlevel to be consistent with java-logging * fix easymock expectation failure
1 parent eabbb78 commit 34a9539

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ See [Logback filters](https://logback.qos.ch/manual/filters.html#thresholdFilter
8989
<!-- Optional: defaults to "java.log" -->
9090
<log>application.log</log>
9191

92-
<!-- Optional: defaults to "ERROR" -->
92+
<!-- Optional: defaults to "OFF" -->
9393
<flushLevel>WARN</flushLevel>
9494

9595
<!-- Optional: defaults to ASYNC -->

samples/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<!--
1515
The parent pom defines common style checks and testing strategies for our samples.
16-
Removing or replacing it should not affect the execution of the samples in anyway.
16+
Removing or replacing it should not affect the execution of the samples in any way.
1717
-->
1818
<parent>
1919
<groupId>com.google.cloud.samples</groupId>

src/main/java/com/google/cloud/logging/logback/LoggingAppender.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
* &lt;!-- Optional: defaults to {@code "java.log"} --&gt;
6363
* &lt;log&gt;application.log&lt;/log&gt;
6464
*
65-
* &lt;!-- Optional: defaults to {@code "ERROR"} --&gt;
65+
* &lt;!-- Optional: defaults to {@code "OFF"} --&gt;
6666
* &lt;flushLevel&gt;WARN&lt;/flushLevel&gt;
6767
*
6868
* &lt;!-- Optional: defaults to {@code ASYNC} --&gt;
@@ -150,7 +150,7 @@ public class LoggingAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {
150150
/**
151151
* Sets a threshold for log severity level to flush all log entries that were batched so far.
152152
*
153-
* <p>Defaults to Error.
153+
* <p>Defaults to OFF.
154154
*
155155
* @param flushLevel Logback log level
156156
*/
@@ -298,7 +298,7 @@ void setupMonitoredResource(MonitoredResource monitoredResource) {
298298
}
299299

300300
private Level getFlushLevel() {
301-
return (flushLevel != null) ? flushLevel : Level.ERROR;
301+
return (flushLevel != null) ? flushLevel : Level.OFF;
302302
}
303303

304304
private String getLogName() {

src/test/java/com/google/cloud/logging/logback/LoggingAppenderTest.java

+7-12
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,15 @@ public void testFlushLevelConfigSupportsFlushLevelOff() {
193193
assertThat(foundSeverity).isEqualTo(null);
194194
}
195195

196+
@Test
197+
public void testDefaultFlushLevelOff() {
198+
loggingAppender.start();
199+
Severity foundSeverity = logging.getFlushSeverity();
200+
assertThat(foundSeverity).isEqualTo(null);
201+
}
202+
196203
@Test
197204
public void testFilterLogsOnlyLogsAtOrAboveLogLevel() {
198-
logging.setFlushSeverity(Severity.ERROR);
199205
Capture<Iterable<LogEntry>> capturedArgument = Capture.newInstance();
200206
logging.write(
201207
capture(capturedArgument),
@@ -223,7 +229,6 @@ public void testFilterLogsOnlyLogsAtOrAboveLogLevel() {
223229

224230
@Test
225231
public void testPartialSuccessOverrideHasExpectedValue() {
226-
logging.setFlushSeverity(Severity.ERROR);
227232
Capture<WriteOption> logNameArg = Capture.newInstance();
228233
Capture<WriteOption> resourceArg = Capture.newInstance();
229234
Capture<WriteOption> partialSuccessArg = Capture.newInstance();
@@ -247,7 +252,6 @@ public void testPartialSuccessOverrideHasExpectedValue() {
247252

248253
@Test
249254
public void testDefaultWriteOptionsHasExpectedDefaults() {
250-
logging.setFlushSeverity(Severity.ERROR);
251255
Capture<WriteOption> partialSuccessArg = Capture.newInstance();
252256
logging.write(
253257
EasyMock.<Iterable<LogEntry>>anyObject(),
@@ -266,7 +270,6 @@ public void testDefaultWriteOptionsHasExpectedDefaults() {
266270

267271
@Test
268272
public void testMdcValuesAreConvertedToLabels() {
269-
logging.setFlushSeverity(Severity.ERROR);
270273
Capture<Iterable<LogEntry>> capturedArgument = Capture.newInstance();
271274
logging.write(
272275
capture(capturedArgument),
@@ -325,7 +328,6 @@ public void testMdcValuesAreConvertedToLabelsWithPassingNullValues() {
325328
MDC.put("mdc1", "value1");
326329
MDC.put("mdc2", null);
327330
MDC.put("mdc3", "value3");
328-
logging.setFlushSeverity(Severity.ERROR);
329331
Capture<Iterable<LogEntry>> capturedArgument = Capture.newInstance();
330332
logging.write(
331333
capture(capturedArgument),
@@ -351,7 +353,6 @@ public void testMdcValuesAreConvertedToLabelsWithPassingNullValues() {
351353
@Test
352354
public void testAddCustomLoggingEventEnhancers() {
353355
MDC.put("mdc1", "value1");
354-
logging.setFlushSeverity(Severity.ERROR);
355356
Capture<Iterable<LogEntry>> capturedArgument = Capture.newInstance();
356357
logging.write(
357358
capture(capturedArgument),
@@ -375,7 +376,6 @@ public void testAddCustomLoggingEventEnhancers() {
375376

376377
@Test
377378
public void testAddCustomLoggingEnhancer() {
378-
logging.setFlushSeverity(Severity.ERROR);
379379
Capture<Iterable<LogEntry>> capturedArgument = Capture.newInstance();
380380
logging.write(
381381
capture(capturedArgument),
@@ -398,7 +398,6 @@ public void testAddCustomLoggingEnhancer() {
398398
@Test
399399
@SuppressWarnings("deprecation")
400400
public void testFlush() {
401-
logging.setFlushSeverity(Severity.ERROR);
402401
logging.write(
403402
EasyMock.<Iterable<LogEntry>>anyObject(),
404403
anyObject(WriteOption.class),
@@ -419,7 +418,6 @@ public void testFlush() {
419418

420419
@Test
421420
public void testAutoPopulationEnabled() {
422-
logging.setFlushSeverity(Severity.ERROR);
423421
Capture<Iterable<LogEntry>> capturedLogEntries = Capture.newInstance();
424422
EasyMock.expect(
425423
logging.populateMetadata(
@@ -458,7 +456,6 @@ public void testAutoPopulationEnabled() {
458456

459457
@Test
460458
public void testRedirectToStdoutEnabled() {
461-
logging.setFlushSeverity(Severity.ERROR);
462459
EasyMock.expect(
463460
logging.populateMetadata(
464461
EasyMock.<Iterable<LogEntry>>anyObject(),
@@ -503,7 +500,6 @@ public void testRedirectToStdoutDisabled() {
503500
public void testFDiagnosticInfoAdded() {
504501
LoggingAppender.setInstrumentationStatus(false);
505502
Capture<Iterable<LogEntry>> capturedArgument = Capture.newInstance();
506-
logging.setFlushSeverity(Severity.ERROR);
507503
logging.write(
508504
capture(capturedArgument),
509505
anyObject(WriteOption.class),
@@ -547,7 +543,6 @@ public void testFDiagnosticInfoAdded() {
547543

548544
@Test
549545
public void testFDiagnosticInfoNotAdded() {
550-
logging.setFlushSeverity(Severity.ERROR);
551546
Capture<Iterable<LogEntry>> capturedArgument = Capture.newInstance();
552547
logging.write(
553548
capture(capturedArgument),

src/test/java/com/google/cloud/logging/logback/logback.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<!-- Optional: defaults to "java.log" -->
99
<log>application.log</log>
1010

11-
<!-- Optional: defaults to "ERROR" -->
11+
<!-- Optional: defaults to "OFF" -->
1212
<flushLevel>WARN</flushLevel>
1313

1414
<!-- Optional: defaults to ASYNC -->

0 commit comments

Comments
 (0)