log.java

来自「Java mulitplayer strategy game. Adaptati」· Java 代码 · 共 143 行

JAVA
143
字号
/*
 * Created on 2004-08-26
 *
 */
package net.sf.jawp.util;

import org.apache.log4j.Logger;

/**
 * Utility class for fast logs using assertions this is simple wrapper for log4j
 * with same API however by default it has debug( Throwable ) methods so that
 * developers do not have to worry about forgeting to pass stacktrace as second
 * param
 * 
 * @version $Revision: 1.3 $
 *          <p>
 *          <b>The latest changes:</b><br/> $Date: 2005/09/15 21:02:29 $<br/>
 *          $Author: overmindx $
 *          </p>
 * @author jarek
 */
public class Log
{
	/**
	 * intrnally strored log4j logger
	 */
	private final Logger log;

	/**
	 * 
	 */
	private Log(final Class arg)
	{
		super();
		log = Logger.getLogger(arg);
	}

	/**
	 * the only method of construction
	 * 
	 * @param arg
	 *            the class for which the logger is constructed
	 * @return
	 */
	public static Log getLog(final Class arg)
	{
		return new Log(arg);
	}

	/**
	 * as in log4j
	 * 
	 * @param o
	 * @return true - always - so that it can be put into assertion statement
	 */
	public final boolean debug(final Object o)
	{
		log.debug(o);
		return true;
	}

	/**
	 * as in log4j
	 * 
	 * @param o
	 * @return true - always - so that it can be put into assertion statement
	 */
	public final boolean debug(final Throwable o)
	{
		log.debug(o, o);
		return true;
	}

	/**
	 * as in log4j
	 * 
	 */
	public final boolean debug(final Object o, final Throwable t)
	{
		log.debug(o, t);
		return true;
	}

	/**
	 * as in log4j
	 * 
	 */
	public final void info(final Object o)
	{
		log.info(o);
	}

	public final void info(final Throwable t)
	{
		log.info(t, t);
	}

	public final void info(final Object o, final Throwable t)
	{
		log.info(o, t);
	}

	/**
	 * as in log4j
	 * 
	 */
	public final void warn(final Object o)
	{
		log.warn(o);
	}

	public final void warn(final Throwable t)
	{
		log.warn(t, t);
	}

	public final void warn(final Object o, final Throwable t)
	{
		log.warn(o, t);
	}

	public final void error(final Object o)
	{
		log.error(o);
	}

	public final void error(final Object o, final Throwable t)
	{
		log.error(o, t);
	}

	public final void error(final Throwable t)
	{
		log.error(t, t);
	}

	// query
	public final boolean isDebugEnabled()
	{
		return log.isDebugEnabled();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?