annotate src/goodjava/logger/ThreadLocalAppender.java @ 1474:13cbce740e1e

LowercaseAnalyzer
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 17 Apr 2020 21:53:09 -0600
parents 219f2b937f2b
children 74c534de211f
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;
1450
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 public final ThreadLocal<Appender> threadLocal = new ThreadLocal<Appender>();
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 }