Chinaunix

标题: log [打印本页]

作者: wzi-linux    时间: 2009-08-20 11:59
标题: log
package com.wm.affnet.util;
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
public class AppLogger {
// static {
//  Properties props = new Properties();
//  System.setProperty("log4j.properties", "true");//yzy set the system property
//  FileInputStream istream = null;
//  try {
//   istream = new FileInputStream("src/log4j.properties");
//   props.load(istream);
//   istream.close();
//  } catch (Exception e) {
//   e.printStackTrace();// yzy how to deal with
//  } finally {
//   if (istream != null) {
//    try {
//     istream.close();
//    } catch (Throwable ignore) {
//    }
//
//   }
//  }
//  props.setProperty("log4j.rootLogger", "ERROR,A1");
//  PropertyConfigurator.configure(props);
// }
@SuppressWarnings("deprecation")
public static void writeLog(Class clz, String info) {
  Logger log = Logger.getLogger(clz);
  if (log.isEnabledFor(Priority.DEBUG)) {
   log.debug(info);
   return;
  }
  if (log.isEnabledFor(Priority.INFO)) {
   log.info(info);
   return;
  }
  if (log.isEnabledFor(Priority.WARN)) {
   log.warn(info);
   return;
  }
  if (log.isEnabledFor(Priority.ERROR)) {
   log.error(info);
   return;
  }
  if (log.isEnabledFor(Priority.FATAL)) {
   log.fatal(info);
   return;
  }
}
public static void debug(Class clz, String info) {
   Logger.getLogger(clz).debug(info);
}
public static void info(Class clz, String info) {
  Logger.getLogger(clz).info(info);
}
public static void warn(Class clz, String info) {
  Logger.getLogger(clz).warn(info);
}
public static void error(Class clz, String info) {
  Logger.getLogger(clz).error(info);
}

public static void error(Class clz, String info,Throwable t) {
  Logger.getLogger(clz).error(info,t);
}
public static void fatal(Class clz, String info) {
  Logger.getLogger(clz).fatal(info);
}
}


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/103458/showart_2032710.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2