Skip to content

Commit

Permalink
feat: expose flush() method in LoggingAppender (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
suraj-qlogic committed Apr 1, 2020
1 parent 9078709 commit 70375e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Expand Up @@ -245,6 +245,16 @@ Logging getLogging() {
return logging;
}

/** Flushes any pending asynchronous logging writes. */
public void flush() {
if (!isStarted()) {
return;
}
synchronized (this) {
getLogging().flush();
}
}

/** Gets the {@link LoggingOptions} to use for this {@link LoggingAppender}. */
protected LoggingOptions getLoggingOptions() {
if (loggingOptions == null) {
Expand Down
Expand Up @@ -305,6 +305,24 @@ public void testAddCustomLoggingEventEnhancers() {
assertThat(capturedArgumentMap.get("bar")).isEqualTo("bar");
}

@Test
public void testFlush() {
logging.setFlushSeverity(Severity.ERROR);
Capture<Iterable<LogEntry>> capturedArgument = Capture.newInstance();
logging.write(capture(capturedArgument), (WriteOption) anyObject(), (WriteOption) anyObject());
expectLastCall().times(2);
logging.flush();
replay(logging);
loggingAppender.start();
Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(100000, 0);
LoggingEvent firstLoggingEvent = createLoggingEvent(Level.WARN, timestamp.getSeconds());
LoggingEvent secondLoggingEvent = createLoggingEvent(Level.INFO, timestamp.getSeconds());
loggingAppender.doAppend(firstLoggingEvent);
loggingAppender.doAppend(secondLoggingEvent);
loggingAppender.flush();
verify(logging);
}

static class CustomLoggingEventEnhancer1 implements LoggingEventEnhancer {

@Override
Expand Down

0 comments on commit 70375e1

Please sign in to comment.