Chinaunix首页 | 论坛 | 博客
  • 博客访问: 14217
  • 博文数量: 12
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 125
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-19 15:05
文章分类

全部博文(12)

文章存档

2011年(1)

2009年(11)

我的朋友
最近访客
log

分类: Java

2009-08-20 11:59:51

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);
 }
}
阅读(387) | 评论(0) | 转发(0) |
0

上一篇:utils

下一篇:send email

给主人留下些什么吧!~~