log4j

package log4j;

import org.apache.log4j.Logger;



public class TestLog4j {
static Logger logger = Logger.getLogger (TestLog4j.class.getClass()) ;
public static void main(String[] args) {
    //使用缺省环境来配置Log4j
//   BasicConfigurator.configure();
//使用配置文件来配置Log4j
// PropertyConfigurator.configure ( "D://testLog4j.properties" ) ;

    //插入日志信息
    logger.info("HelloLog4j开始执行");
    try {
      TestLog4j Log4j = new TestLog4j();
      int count=Log4j.count(1,0);
      logger.debug("count的值为:"+count);
    }
    catch (Exception e) {
      logger.error("error"+e.getMessage());
    }
    logger.info("HelloLog4j执行完成");   
  }
  /**
   * 求两整数数之和
   * */
  public int count(int a,int b) {
    int add=a/b;
    if (add<0){
      logger.warn("两数之和小于零");
    }
    return 1000;
  }
}

你可能感兴趣的:(log4j)