package com.munzenberger.feed.log;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

public class Logger {
	
	private final List<Appender> appenders = new LinkedList<Appender>();
	
	public void addAppender(Appender appender) {
		appenders.add(appender);
	}

	public void info(String message) {
		append("[INFO]", message);
	}

	public void error(String message, Throwable cause) {
		append("[ERROR]", message, cause);
	}
	
	private void append(String level, String message) {
		append(level, message, null);
	}
	
	private void append(String level, String message, Throwable cause) {
		String formattedMessage = formatMessage(level, message, cause);
		for (Appender a : appenders) {
			a.append(formattedMessage);
		}
	}
	
	private static String time() {
		return new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a").format(new Date());
	}
	
	private static String formatMessage(String level, String message, Throwable cause) {
		StringBuilder sb = new StringBuilder();
		
		sb.append(time()).append(" ").append(level).append(" ").append(message);
		
		if (cause != null) {
			StringWriter sw = new StringWriter();
			PrintWriter pw = new PrintWriter(sw);
			cause.printStackTrace(pw);
			pw.flush();
			pw.close();
			sb.append("\n").append(sw.toString());
		}
		
		return sb.toString();
	}
}

@@ -221,16 +221,97 @@
 ger %7B%0A%09%0A
+%09private static final String separator = System.getProperty(%22line.separator%22);%0A%09%0A
 %09private
@@ -1418,12 +1418,17 @@
 end(
-%22%5Cn%22
+separator
 ).ap

use system line separator