view src/goodjava/logger/ThreadLocalAppender.java @ 1451:85d7c1777357

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 01 Mar 2020 13:58:27 -0700
parents 28b1ddacfad3
children 219f2b937f2b
line wrap: on
line source

package goodjava.logger;


public final 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();
	}
}