Java by API/org.apache.commons.lang.time/Logging

Материал из Java эксперт
Версия от 14:15, 31 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

LogFactory: getLog(Class cls)

/*
The Log being used >>> org.apache.rumons.logging.impl.Jdk14Logger@a97b0b
Jun 10, 2006 1:37:28 PM LoggingTrial main
INFO: INFO TEST
Jun 10, 2006 1:37:29 PM LoggingTrial main
INFO: INFO TEST
java.lang.Exception: A DUMMY EXCEPTION
  at LoggingTrial.main(LoggingTrial.java:9)
Jun 10, 2006 1:37:29 PM LoggingTrial main
WARNING: WARN TEST
Jun 10, 2006 1:37:29 PM LoggingTrial main
WARNING: WARN TEST
java.lang.Exception: A DUMMY EXCEPTION
  at LoggingTrial.main(LoggingTrial.java:9)
Jun 10, 2006 1:37:29 PM LoggingTrial main
SEVERE: ERROR TEST
Jun 10, 2006 1:37:29 PM LoggingTrial main
SEVERE: ERROR TEST
java.lang.Exception: A DUMMY EXCEPTION
  at LoggingTrial.main(LoggingTrial.java:9)
Jun 10, 2006 1:37:29 PM LoggingTrial main
SEVERE: FATAL TEST
Jun 10, 2006 1:37:29 PM LoggingTrial main
SEVERE: FATAL TEST
java.lang.Exception: A DUMMY EXCEPTION
  at LoggingTrial.main(LoggingTrial.java:9)
 
 */
import org.apache.rumons.logging.Log;
import org.apache.rumons.logging.LogFactory;
public class LoggingTrial {
  public static void main(String[] args) {
    Log log = LogFactory.getLog(LoggingTrial.class);
    System.out.println("The Log being used >>> " + log);
    Exception e = new Exception("A DUMMY EXCEPTION");
    if (log.isTraceEnabled()) {
      log.trace("TRACE TEST");
      log.trace("TRACE TEST", e);
    }
    if (log.isDebugEnabled()) {
      log.debug("DEBUG TEST");
      log.debug("DEBUG TEST", e);
    }
    if (log.isInfoEnabled()) {
      log.info("INFO TEST");
      log.info("INFO TEST", e);
    }
    if (log.isWarnEnabled()) {
      log.warn("WARN TEST");
      log.warn("WARN TEST", e);
    }
    if (log.isErrorEnabled()) {
      log.error("ERROR TEST");
      log.error("ERROR TEST", e);
    }
    if (log.isFatalEnabled()) {
      log.fatal("FATAL TEST");
      log.fatal("FATAL TEST", e);
    }
  }
}