/*
 * Copyright (c) 2002-2012 JSCAPE
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JSCAPE. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JSCAPE.
 */

package com.jscape.util.log;

import com.jscape.util.ExceptionTools;
import com.jscape.util.SuppressObfuscation;

import java.util.Calendar;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;

/**
 * @author Alex
 */
@SuppressObfuscation
public class SimpleFormatter
        extends Formatter {

    private static final String TEMPLATE = "%1$tm.%1$td.%1$tY %1$tH:%1$tM:%1$tS [%2$7s] %3$s%n%4$s";

    @Override
    public String format(LogRecord record) {
        return String.format(TEMPLATE,
                             Calendar.getInstance(),
                             record.getLevel().getLocalizedName(),
                             formatMessage(record),
                             record.getThrown() != null ? ExceptionTools.stackTraceOf(record.getThrown()) : "");
    }

}