diff src/goodjava/logger/ThreadLocalAppender.java @ 1450:28b1ddacfad3

logger work
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 01 Mar 2020 13:47:02 -0700
parents
children 85d7c1777357
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/goodjava/logger/ThreadLocalAppender.java	Sun Mar 01 13:47:02 2020 -0700
@@ -0,0 +1,22 @@
+package goodjava.logger;
+
+
+public class ThreadLocalAppender implements Appender {
+	private final Appender defaultAppender;
+	public final ThreadLocal<Appender> threadLocal = new ThreadLocal<Appender>();
+
+	public ThreadLocalAppender(Appender defaultAppender) {
+		this.defaultAppender = defaultAppender;
+	}
+
+	public void append(LoggingEvent event) {
+		Appender appender = threadLocal.get();
+		if( appender == null )
+			appender = defaultAppender;
+		appender.append(event);
+	}
+
+	public void close() {
+		defaultAppender.close();
+	}
+}