/*
 * $Id: VKCWebDavFormatter.java,v 1.1 2007/08/01 14:56:48 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 */

package vkc.misc;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;

public class VKCWebDavFormatter extends Formatter {
    SimpleDateFormat formatter = new SimpleDateFormat("[dd/MMM/yyyy:HH:mm:ss Z]");

    public String format(LogRecord logRecord) {
        StringBuffer buf = new StringBuffer();

        String time = formatter.format(new Date(logRecord.getMillis())) + " ";
        Object[] params = logRecord.getParameters();

        if (params != null) {
            for (int i = 0; i < params.length; i++) {
                if (params[i] == null) {
                    buf.append("- ");
                } else {
                    if (((String) params[i]).equals("date")) {
                        buf.append(time);
                    } else {
                        buf.append(params[i] + " ");
                    }
                }
            }
        }

        buf.append("\n");

        return buf.toString();
    }
}