Skip to content

Instantly share code, notes, and snippets.

@wkorando
Last active August 6, 2018 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wkorando/55b8633aeae0e70415874ef6eea6adf6 to your computer and use it in GitHub Desktop.
Save wkorando/55b8633aeae0e70415874ef6eea6adf6 to your computer and use it in GitHub Desktop.
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