annotate src/goodjava/logger/ThreadLocalAppender.java @ 1673:1b9f9fdb3b41

remove backup password
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 28 May 2022 21:00:30 -0600
parents 74c534de211f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1450
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 package goodjava.logger;
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3
1451
Franklin Schmidt <fschmidt@gmail.com>
parents: 1450
diff changeset
4 public final class ThreadLocalAppender implements Appender {
1454
219f2b937f2b remove log4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 1451
diff changeset
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
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 public ThreadLocalAppender(Appender defaultAppender) {
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 this.defaultAppender = defaultAppender;
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 }
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 public void append(LoggingEvent event) {
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 Appender appender = threadLocal.get();
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 if( appender == null )
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 appender = defaultAppender;
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 appender.append(event);
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 }
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 public void close() {
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 defaultAppender.close();
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 }
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 }