Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2015
What would you like to do?
How to create a Log4J Logger for unit testing Java code that logs
LoggingEvent loggedEvent = null;
private Logger capturingLogger() {
return new Logger("testing") {
level = Level.ALL;
repository = mock(LoggerRepository.class);
public void callAppenders(LoggingEvent event) {
assertNull("expected only one event", loggedEvent);
loggedEvent = event;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment