annotate 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
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 {
1450
28b1ddacfad3 logger work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 private final Appender defaultAppender;
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 }