blob: 3eff2fb50c7b8863ad2cfee2cbbae6b35518a863 [file] [log] [blame]
/*
* Copyright (C) MX4J.
* All rights reserved.
*
* This software is distributed under the terms of the MX4J License version 1.0.
* See the terms of the MX4J License in the documentation provided with this software.
*/
/*
* Copyright 2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.felix.mosgi.jmx.agent.mx4j.log;
/**
* Base class for logging objects.
*
* @author <a href="mailto:biorn_steedom@users.sourceforge.net">Simone Bordet</a>
* @version $Revision: 1.1.1.1 $
*/
public class Logger
{
public static final int TRACE = 0;
public static final int DEBUG = TRACE + 10;
public static final int INFO = DEBUG + 10;
public static final int WARN = INFO + 10;
public static final int ERROR = WARN + 10;
public static final int FATAL = ERROR + 10;
private int m_priority = WARN;
private String m_category;
protected Logger() {}
public void setPriority(int priority) {m_priority = priority;}
public int getPriority() {return m_priority;}
public String getCategory() {return m_category;}
protected void setCategory(String category) {m_category = category;}
public final boolean isEnabledFor(int priority)
{
return priority >= getPriority();
}
public final void fatal(Object message) {log(FATAL, message, null);}
public final void fatal(Object message, Throwable t) {log(FATAL, message, t);}
public final void error(Object message) {log(ERROR, message, null);}
public final void error(Object message, Throwable t) {log(ERROR, message, t);}
public final void warn(Object message) {log(WARN, message, null);}
public final void warn(Object message, Throwable t) {log(WARN, message, t);}
public final void info(Object message) {log(INFO, message, null);}
public final void info(Object message, Throwable t) {log(INFO, message, t);}
public final void debug(Object message) {log(DEBUG, message, null);}
public final void debug(Object message, Throwable t) {log(DEBUG, message, t);}
public final void trace(Object message) {log(TRACE, message, null);}
public final void trace(Object message, Throwable t) {log(TRACE, message, t);}
protected void log(int priority, Object message, Throwable t)
{
if (isEnabledFor(priority))
{
System.out.println(message);
if (t != null)
{
t.printStackTrace(System.out);
}
}
}
}