Last active
August 6, 2018 20:27
-
-
Save wkorando/55b8633aeae0e70415874ef6eea6adf6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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