/*
 * 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 java.io.OutputStream;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
import java.util.logging.StreamHandler;

/**
 * @author Roman Sheshunov
 */
public class DebugStreamHandler
        extends StreamHandler {

    private final OutputStream out;

    public DebugStreamHandler(OutputStream out, Formatter formatter) {
        super(out, formatter);
        this.out = out;
    }

    public DebugStreamHandler(OutputStream out) {
        this(out, new DebugFormatter());
    }

    @Override
    public void publish(LogRecord record) {
        if (isLoggable(record)) {
            super.publish(record);
            flush();
        }
    }

    public OutputStream stream() {
        return this.out;
    }
}