package koncept.util;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ExceptionRecordingLogger extends Logger {
	public final List<LogMessage> logs = new ArrayList<>();
	
	public ExceptionRecordingLogger() {
		this(ExceptionRecordingLogger.class.getName());
	}
	public ExceptionRecordingLogger(String name) {
		super(name, null);
	}
	
	@Override
	public void log(Level level, String msg) {
		super.log(level, msg);
		logs.add(new LogMessage(level, msg, null));
	}
	
	@Override
	public void log(Level level, String msg, Throwable thrown) {
		super.log(level, msg, thrown);
		logs.add(new LogMessage(level, msg, thrown));
	}
	
	
	public void output(PrintStream out) {
		for(LogMessage log: logs) {
			out.println(log);
		}
	}
	
	public static class LogMessage {
		public final Level level;
		public final String msg;
		public final Throwable thrown;
		
		public LogMessage(Level level, String msg, Throwable thrown) {
			this.level = level;
			this.msg = msg;
			this.thrown = thrown;
		}
		
		@Override
		public String toString() {
			if (thrown == null)
				return level + ":" + msg;
			return level + ":" + msg + ":" + thrown;
		}
	}
	
}
@@ -72,24 +72,55 @@
 ArrayList;%0D%0A
+import java.util.Collections;%0D%0A
 import java.
@@ -294,16 +294,45 @@
  logs = 
+Collections.synchronizedList(
 new Arra
@@ -341,11 +341,22 @@
 ist%3C
+LogMessage
 %3E()
+)
 ;%0D%0A%09

synchronize recording test logger