Mercurial Hosting > luan
comparison src/goodjava/logger/WriterAppender.java @ 1448:6fc083e1d08c
start logger
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Sun, 23 Feb 2020 18:14:32 -0700 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1447:851b9a48cc44 | 1448:6fc083e1d08c |
|---|---|
| 1 package goodjava.logger; | |
| 2 | |
| 3 import java.io.Writer; | |
| 4 import java.io.IOException; | |
| 5 | |
| 6 | |
| 7 public class WriterAppender implements Appender { | |
| 8 protected final Layout layout; | |
| 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 } |
