Mercurial Hosting > luan
annotate src/goodjava/logger/ThreadLocalAppender.java @ 1624:fe611f6e3c28
more content types
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 07 Aug 2021 20:01:46 -0600 |
parents | 74c534de211f |
children |
rev | line source |
---|---|
1450 | 1 package goodjava.logger; |
2 | |
3 | |
1451 | 4 public final class ThreadLocalAppender implements Appender { |
1454 | 5 public volatile Appender defaultAppender; |
1503
74c534de211f
use InheritableThreadLocal in ThreadLocalAppender
Franklin Schmidt <fschmidt@gmail.com>
parents:
1454
diff
changeset
|
6 public final ThreadLocal<Appender> threadLocal = new InheritableThreadLocal<Appender>(); |
1450 | 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 } |