Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class ThreadSafeAppender extends AppenderBase<ILoggingEvent> {
static ThreadLocal<List<ILoggingEvent>> threadLocal = new ThreadLocal<>();
@Override
public void append(ILoggingEvent e) {
List<ILoggingEvent> events = threadLocal.get();
if (events == null) {
events = new ArrayList<>();
threadLocal.set(events);
}
events.add(e);
}
public static List<ILoggingEvent> getEvents() {
return threadLocal.get();
}
public static void clearEvents() {
threadLocal.remove();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment