defaultlogger.java

来自「这是一个mvc模式」· Java 代码 · 共 123 行

JAVA
123
字号
package jsp.tags.dapact.util;
/**
 * Title:        Data Aware Processing And Control Tags
 * Description:  Tag library for the processing and controlling the input and output of data.
 * Copyright:    LGPL (http://www.gnu.org/copyleft/lesser.html)
 * Compile Date: @compile_date@      
 * @author Allen M Servedio
 * @amp_sign@version @VERSION@
 */

/**
 * Default implementation of the logger interface - just logs everything to system out
 * or system error.
 */
public class DefaultLogger implements LoggerInf
{

  public DefaultLogger()
  {
  }

  /**
   * Log a Throwable - since no type is specified, this should be considered an error.
   *
   * @param e the Throwable to log.
   */
  public void log(Throwable e)
  {
    System.err.print(LazyDate.getInstance().todaysDateWithSpace());
    e.printStackTrace(System.err);
  }

  /**
   * Log a message - since no type is specified, this should be considered info.
   *
   * @param msg a message to log.
   */
  public void log(String msg)
  {
    System.out.print(LazyDate.getInstance().todaysDateWithSpace());
    System.out.println(msg);
  }

  /**
   * Log a Throwable with an extra message - since no type is specified, this should be considered an error.
   *
   * @param msg an extra message to include with the Throwable.
   * @param e the Throwable to log.
   */
  public void log(String msg, Throwable e)
  {
    System.err.print(LazyDate.getInstance().todaysDateWithSpace());
    System.err.println(msg);
    e.printStackTrace(System.err);
  }

  /**
   * Log a Throwable with a log type.
   *
   * @param type one of the log types specified in the LogTypes interface.
   * @param e the Throwable to log.
   */
  public void log(int type, Throwable e)
  {
    switch (type)
    {
      case LoggerInf.LogTypes.ERROR:
        System.err.print(LazyDate.getInstance().todaysDateWithSpace());
        e.printStackTrace(System.err);
      break;
      default:
        System.out.print(LazyDate.getInstance().todaysDateWithSpace());
        e.printStackTrace(System.out);
      break;
    }
  }

  /**
   * Log a Throwable with an extra message.
   *
   * @param type one of the log types specified in the LogTypes interface.
   * @param msg an extra message to include with the Throwable.
   * @param e the Throwable to log.
   */
  public void log(int type, String msg, Throwable e)
  {
    switch (type)
    {
      case LoggerInf.LogTypes.ERROR:
        System.err.print(LazyDate.getInstance().todaysDateWithSpace());
        System.err.println(msg);
        e.printStackTrace(System.err);
      break;
      default:
        System.out.print(LazyDate.getInstance().todaysDateWithSpace());
        System.out.println(msg);
        e.printStackTrace(System.out);
      break;
    }
  }

  /**
   * Log a message.
   *
   * @param type one of the log types specified in the LogTypes interface.
   * @param msg an extra message to include with the Throwable.
   */
  public void log(int type, String msg)
  {
    switch (type)
    {
      case LoggerInf.LogTypes.ERROR:
        System.err.print(LazyDate.getInstance().todaysDateWithSpace());
        System.err.println(msg);
      break;
      default:
        System.out.print(LazyDate.getInstance().todaysDateWithSpace());
        System.out.println(msg);
      break;
    }
  }
}

⌨️ 快捷键说明

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