In unit tests, it can be useful to suppress all logging for successful tests, but still log everything when tests fail. In order to accomplish this, we need to buffer all logging before we know the result of the test, and then flush or clear the buffer once we know the outcome. BufferedAppender is the logback appender that buffers all logging until it receives a or marker. You can use directly in logback configuration. It requires a delegate appender for flushing, declared using an . tagName configuration attributes name packagingData value "true" children tagName appender attributes name name value "Console" name class value "ch.qos.logback.core.ConsoleAppender" children tagName encoder attributes children tagName pattern attributes children tagName text %highlight(%-5level) %cyan(%date{HH:mm:ss.SSS, ${LOGGING_TIMEZONE}}) %gray(\(%file:%line\)) [%white(%thread)] %blue(%marker) {%magenta(%mdc)} %green(%logger): %message%n%rootException tagName appender attributes name name value "Buffered" name class value "io.liftwizard.logging.logback.appender.buffered.BufferedAppender" children tagName appender-ref attributes name ref value "Console" children tagName root attributes name level value "INFO" children tagName appender-ref attributes name ref value "Buffered" children lives in the module. Log Markers We must log and markers to instruct to clear or flush its logs. If you are using JUnit 4 or 5, you can use the included Rule or Extension to log these markers automatically. JUnit 4 is a JUnit 4 that clears the buffer before all tests and flushes the buffer after failed tests. It does this by logging and markers. lives in the module. LogMarkerTestRule Rule CLEAR FLUSH public class ExampleTest { @Rule public final TestRule logMarkerTestRule = new LogMarkerTestRule(); @Test public void smokeTest() { // test code } } LogMarkerTestRule liftwizard-junit-rule-log-marker <dependency> <groupId>io.liftwizard</groupId> <artifactId>liftwizard-junit-rule-log-marker</artifactId> <scope>test</scope> </dependency> JUnit 5 is a JUnit 5 that clears the buffer before all tests and flushes the buffer after failed tests. It does this by logging and markers. lives in the module. LogMarkerTestExtension Extension CLEAR FLUSH @ExtendWith(LogMarkerTestExtension.class) public class ExampleTest { @Test public void smokeTest() { // test code } } LogMarkerTestExtension liftwizard-junit-extension-log-marker <dependency> <groupId>io.liftwizard</groupId> <artifactId>liftwizard-junit-extension-log-marker</artifactId> <scope>test</scope> </dependency> BufferedAppenderFactory The allows you to use an appender with the type where you would otherwise use in your Dropwizard configuration. lives in the module. Note: is primarily useful for tests that use Dropwizard's JUnit 4 Rule or Dropwizard's JUnit 5 Extension . JUnit 4 needs to be an inner rule when used together with DropwizardAppRule. Both rules tear down logging, and needs to perform its tear down first, to flush its contents to the console. LogMarkerTestRule LogMarkerTestRule private final TestRule logMarkerTestRule = new LogMarkerTestRule(); private final DropwizardAppRule<MyAppConfiguration> dropwizardAppRule = new DropwizardAppRule<>( MyApplication.class, ResourceHelpers.resourceFilePath("test-example.json5")); @Rule public final RuleChain ruleChain = RuleChain .outerRule(this.dropwizardAppRule) .around(this.logMarkerTestRule); JUnit 5 was used as an annotation in the previous example. When used together with , it ought to be a field to control execution order. Both extensions tear down logging, and needs to perform its tear down first, to flush its contents to the console. LogMarkerTestExtension DropwizardAppExtension LogMarkerTestExtension @RegisterExtension final DropwizardAppExtension<MyAppConfiguration> dropwizardAppExtension = new DropwizardAppExtension<>( MyApplication.class, ResourceHelpers.resourceFilePath("test-example.json5")); @RegisterExtension final LogMarkerTestExtension logMarkerTestExtension = new LogMarkerTestExtension(); BufferedAppender CLEAR FLUSH appender-ref BufferedAppender liftwizard-logging-buffered-appender <dependency> <groupId>io.liftwizard</groupId> <artifactId>liftwizard-logging-buffered-appender</artifactId> <scope>test</scope> </dependency> CLEAR FLUSH BufferedAppender BufferedAppenderFactory buffered console "logging": { "level": "DEBUG", "appenders": [ { "type": "buffered", "timeZone": "${LOGGING_TIMEZONE:-system}", "logFormat": "%highlight(%-5level) %cyan(%date{HH:mm:ss.SSS, %dwTimeZone}) %gray(\\(%file:%line\\)) [%white(%thread)] %blue(%marker) {%magenta(%mdc)} %green(%logger): %message%n%rootException", "includeCallerData": true, }, ] } BufferedAppenderFactory liftwizard-config-logging-buffered <dependency> <groupId>io.liftwizard</groupId> <artifactId>liftwizard-config-logging-buffered</artifactId> <scope>test</scope> </dependency> BufferedAppenderFactory DropwizardAppRule DropwizardAppExtension