/*
 * VerySimpleFormatter.java
 *
 * Created on 13 March 2003, 11:38
 */

package org.bodington.logging;

import java.util.logging.*;
import java.io.*;

/**
 *
 * @author  jrm
 */
public class VerySimpleFormatter extends java.util.logging.SimpleFormatter
{
    StringBuffer sb = new StringBuffer();

    // Line separator string.  This is the value of the line.separator
    // property at the moment that the SimpleFormatter was created.
    private String lineSeparator = (String) java.security.AccessController.doPrivileged(
               new sun.security.action.GetPropertyAction("line.separator"));

    /**
     * Format the given LogRecord.
     * @param record the log record to be formatted.
     * @return a formatted log record
     */
    public synchronized String format(LogRecord record)
        {
	sb.setLength( 0 );
        
	sb.append( record.getMillis() );
        
	sb.append(" ");
	String message = formatMessage(record);
	sb.append(" ");
	sb.append(message);
	sb.append(lineSeparator);
	if (record.getThrown() != null) {
	    try {
	        StringWriter sw = new StringWriter();
	        PrintWriter pw = new PrintWriter(sw);
	        record.getThrown().printStackTrace(pw);
	        pw.close();
		sb.append(sw.toString());
	    } catch (Exception ex) {
	    }
	}
	return sb.toString();
    }
    
}
