package nl.nikhef.safaripark;

import java.awt.TextArea;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import javax.swing.SwingUtilities;

@SuppressWarnings("serial")
public class ActiveLogArea extends TextArea {
	
	private SimpleFormatter _format = new SimpleFormatter();
	
	public ActiveLogArea() {
		
		setEditable(false);
		
		Logger gLogger = Logger.getLogger("");
		System.out.println(gLogger);
		gLogger.addHandler(new Handler() {
			
			@Override
			public void publish(final LogRecord record) {
		        SwingUtilities.invokeLater(new Runnable() {

		            @Override
		            public void run() {
		                String txt = String.format("[%s] %s (%s)\n", record.getLevel(), _format.formatMessage(record), record.getLoggerName());
		                System.out.println(txt);
		                append(txt);
		            }

		        });
		 
			}
			
			@Override
			public void flush() {
			}
			
			@Override
			public void close() throws SecurityException {
			}
		});
	}
	

}
