package se.tada.tests;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Filter;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;

public class LogHandler extends Handler
{
	public void publish(LogRecord record)
	{
		System.out.println("In LogHandler.publish()");
		System.out.println(this.getFormatter().format(record));
	}

	public LogHandler()
	{
		System.out.println("In LogHandler()");
		this.setFormatter(new LogFormatter());
	}

	public void flush()
	{
	}

	public void close()
	{
	}

	public static void init()
	{
		System.out.println("In LogHandler.init()");
		Properties props = new Properties();
		props.setProperty("handlers", LogHandler.class.getName());
		props.setProperty(".level", "FINE");
		ByteArrayOutputStream po = new ByteArrayOutputStream();
		try
		{
			props.store(po, null);
			LogManager.getLogManager().readConfiguration(
				new ByteArrayInputStream(po.toByteArray()));
		}
		catch(IOException e)
		{
		}
	}
}
