comparison 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
comparison
equal deleted inserted replaced
1449:dd14d2dce7ee 1450:28b1ddacfad3
1 package goodjava.logger;
2
3
4 public class ThreadLocalAppender implements Appender {
5 private final Appender defaultAppender;
6 public final ThreadLocal<Appender> threadLocal = new ThreadLocal<Appender>();
7
8 public ThreadLocalAppender(Appender defaultAppender) {
9 this.defaultAppender = defaultAppender;
10 }
11
12 public void append(LoggingEvent event) {
13 Appender appender = threadLocal.get();
14 if( appender == null )
15 appender = defaultAppender;
16 appender.append(event);
17 }
18
19 public void close() {
20 defaultAppender.close();
21 }
22 }