/*
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999 Bull S.A.
 * Contact: jonas-team@objectweb.org
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */

package util;

import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;
import org.objectweb.util.monolog.api.LoggerFactory;
import org.objectweb.util.monolog.Monolog;


/**
 * This class is provided only for backward compatibility for old test suite.
 * @author Philippe Durieux
 */
public class Trace {



    public static final int DB_1 = (1<<1);
    public static final int DB_31 = (1<<31);

    public static String filename = "trace.properties";
    public static LoggerFactory loggerFactory = null;
    private static Logger logger = null;
 
    // constructor is private to prevent client program from instanciating a 'Trace'
    private Trace() {
    }

    /**
     * @return the logger instance for tests
     */
    public static Logger getLogger() {
	if (logger == null) {
	    logger = loggerFactory.getLogger("org.objectweb.jonas_tests");
	}
	return logger;
    }

    /**
     * 
     */
    public static void configure() {
        loggerFactory = Monolog.init(filename);
    }

    /**
     *  Sends the trace message to the trace output device if flag is configured
     * @param f   this flag must be configured to get the message on output
     * @param s   message to send
     */
    public static void outln(int f, String s) {
        getLogger().log(f == DB_1 ? BasicLevel.DEBUG : BasicLevel.WARN, s);
    }

    /**
     *  Sends the trace message to the trace output device.
     * @param s   message to send
     */
    public static void outln(String s) {
        getLogger().log(BasicLevel.WARN, s);
    }

    /**
     *  Sends the trace message to the trace output device.
     * @param s   message to send
     */
    public static void out(String s) {
        outln(s);
    }

    /**
     *  Sends the trace message to the jonas logger as error level.
     * @param s   message to send
     */
    public static void errln(String s) {
        getLogger().log(BasicLevel.ERROR, s);
    }

}

