- 论坛徽章:
- 0
|
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 |
|