Mercurial Hosting > luan
annotate src/goodjava/logger/WriterAppender.java @ 2018:5203eb9b0e02
http utf-8
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Fri, 03 Oct 2025 16:45:33 -0600 |
| parents | 1cdc12cdcfa2 |
| children |
| rev | line source |
|---|---|
| 1448 | 1 package goodjava.logger; |
| 2 | |
| 3 import java.io.Writer; | |
| 4 import java.io.IOException; | |
| 5 | |
| 6 | |
| 7 public class WriterAppender implements Appender { | |
|
2014
1cdc12cdcfa2
make logging more accessible
Franklin Schmidt <fschmidt@gmail.com>
parents:
1448
diff
changeset
|
8 public final Layout layout; |
| 1448 | 9 protected Writer writer; |
| 10 | |
| 11 public WriterAppender(Layout layout,Writer writer) { | |
| 12 this.layout = layout; | |
| 13 this.writer = writer; | |
| 14 } | |
| 15 | |
| 16 public synchronized void append(LoggingEvent event) { | |
| 17 try { | |
| 18 writer.write( layout.format(event) ); | |
| 19 flush(); | |
| 20 } catch(IOException e) { | |
| 21 printStackTrace(e); | |
| 22 } | |
| 23 } | |
| 24 | |
| 25 protected void flush() throws IOException { | |
| 26 writer.flush(); | |
| 27 } | |
| 28 | |
| 29 public void close() { | |
| 30 try { | |
| 31 writer.close(); | |
| 32 } catch(IOException e) { | |
| 33 printStackTrace(e); | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 protected void printStackTrace(IOException e) { | |
| 38 e.printStackTrace(); | |
| 39 } | |
| 40 } |
