view src/goodjava/logger/WriterAppender.java @ 1645:0af6a9d6d12f

minor - keywords
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 03 Mar 2022 22:41:07 -0700 (2022-03-04)
parents 6fc083e1d08c
children
line wrap: on
line source
package goodjava.logger;

import java.io.Writer;
import java.io.IOException;


public class WriterAppender implements Appender {
	protected final Layout layout;
	protected Writer writer;

	public WriterAppender(Layout layout,Writer writer) {
		this.layout = layout;
		this.writer = writer;
	}

	public synchronized void append(LoggingEvent event) {
		try {
			writer.write( layout.format(event) );
			flush();
		} catch(IOException e) {
			printStackTrace(e);
		}
	}

	protected void flush() throws IOException {
		writer.flush();
	}

	public void close() {
		try {
			writer.close();
		} catch(IOException e) {
			printStackTrace(e);
		}
	}

	protected void printStackTrace(IOException e) {
		e.printStackTrace();
	}
}