/*
 * 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 org.objectweb.jonas_ejb.container;

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

/**
 * For message logging
 * @author Sebastien Chassande-Barrioz sebastien.chassande@inrialpes.fr
 *           Monolog for traces
 */
public class TraceEjb {

    static public Logger logger = null;
    static public Logger interp = null;
    static public Logger thread = null;
    static public Logger synchro = null;
    static public Logger swapper = null;
    static public Logger security = null;
    static public Logger mdb = null;
    static public Logger tx = null;
    static public final String prefix = "org.objectweb.jonas_ejb";

    static public void configure(LoggerFactory lf) {
	logger = lf.getLogger(prefix);
	interp = lf.getLogger(prefix + ".interp");
	thread = lf.getLogger(prefix + ".thread");
	synchro = lf.getLogger(prefix + ".synchro");
	swapper = lf.getLogger(prefix + ".swapper");
	security = lf.getLogger(prefix + ".security");
	mdb = lf.getLogger(prefix + ".mdb");
	tx = lf.getLogger(prefix + ".tx");
    }

    static public boolean isVerbose() {
	return (logger != null) && logger.isLoggable(BasicLevel.WARN);
    }
    static public boolean isDebugThread() {
	return (thread != null) && thread.isLoggable(BasicLevel.DEBUG);
    }
    static public boolean isDebugSynchro() {
	return (synchro != null) && synchro.isLoggable(BasicLevel.DEBUG);
    }
    static public boolean isDebugSwapper() {
	return (swapper != null) && swapper.isLoggable(BasicLevel.DEBUG);
    }
    static public boolean isDebugIc() {
	return (interp != null) && interp.isLoggable(BasicLevel.DEBUG);
    }
    static public boolean isDebugSecurity() {
	return (security != null) && security.isLoggable(BasicLevel.DEBUG);
    }
    static public boolean isDebugJms() {
	return (mdb != null) && mdb.isLoggable(BasicLevel.DEBUG);
    }
    static public boolean isDebugTx() {
	return (tx != null) && tx.isLoggable(BasicLevel.DEBUG);
    }

    static public void verbose(String msg) {
	if (logger != null) logger.log(BasicLevel.WARN, msg);
    }

    static public void verbose(String msg1, String msg2) {
	if (isVerbose()) {
	    logger.log(BasicLevel.WARN, msg1 + msg2);
	}
    }

    static public void debugThread(String msg) {
	if (thread != null) thread.log(BasicLevel.DEBUG, msg);
    }

    static public void debugThread(String msg1, String msg2) {
	if (isDebugThread()) {
	    thread.log(BasicLevel.DEBUG, msg1 + msg2);
	}
    }

    static public void debugSynchro(String msg) {
	if (synchro != null) synchro.log(BasicLevel.DEBUG, msg);
    }

    static public void debugSynchro(String msg1, String msg2) {
	if (isDebugSynchro()) {
	    synchro.log(BasicLevel.DEBUG, msg1 + msg2);
	}
    }

    static public void debugSwapper(String msg) {
	if (swapper != null) swapper.log(BasicLevel.DEBUG, msg);
    }

    static public void debugSwapper(String msg1, String msg2) {
	if (isDebugSwapper()) {
	    swapper.log(BasicLevel.DEBUG, msg1 + msg2);
	}
    }

    static public void debugIc(String msg) {
	if (interp != null) interp.log(BasicLevel.DEBUG, msg);
    }

    static public void debugIc(String msg1, String msg2) {
	if (isDebugIc()) {
	    interp.log(BasicLevel.DEBUG, msg1 + msg2);
	}
    }

    static public void debugTx(String msg) {
	if (tx != null) tx.log(BasicLevel.DEBUG, msg);
    }

    static public void debugTx(String msg1, String msg2) {
	if (isDebugTx()) {
	    tx.log(BasicLevel.DEBUG, msg1 + msg2);
	}
    }

    static public void debugSecurity(String msg) {
	if (security != null) security.log(BasicLevel.DEBUG, msg);
    }

    static public void debugJms(String msg) {
	if (mdb != null) mdb.log(BasicLevel.DEBUG, msg);
    }

    static public void error(String msg) {
	if (logger != null) logger.log(BasicLevel.ERROR, msg);
    }

    static public void error(String msg1, String msg2) {
	if (logger != null) logger.log(BasicLevel.ERROR, msg1 + msg2);
    }

    static public void error(String msg, Throwable th) {
	if (logger != null) logger.log(BasicLevel.ERROR, msg, th);
    }

    static public void error(String msg1, String msg2, Throwable th) {
	if (logger != null) logger.log(BasicLevel.ERROR, msg1 + msg2, th);
    }
}
