传统的log4j实战

/**
 * 
 */
package log4j;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 * @author think
 *
 */
public class HelloLog4j {
    private static Logger logger = Logger.getLogger(HelloLog4j.class);  
    
    /** 
     * @param args 
     */  
    public static void main(String[] args) {
        // System.out.println("This is println message.");  
        PropertyConfigurator.configure("D:\\workspace\\test\\src\\log4j\\log4j.properties");
        // 记录debug级别的信息  
        logger.debug("This is debug message.");  
        // 记录info级别的信息  
        logger.info("This is info message.");  
        // 记录error级别的信息  
        logger.error("This is error message.");  
    }
}

 

 

#可以设置级别:debug>info>error  
#debug:显示debug、info、error  
#info:显示info、error  
#error:只error  
log4j.rootLogger=debug,appender1  
#log4j.rootLogger=info,appender1  
#log4j.rootLogger=error,appender1  
  
#输出到控制台  
log4j.appender.appender1=org.apache.log4j.ConsoleAppender  
#样式为TTCCLayout  
log4j.appender.appender1.layout=org.apache.log4j.PatternLayout

log4j.appender.appender1.layout.ConversionPattern=%r [%t] [%p] - %c -%l -%m -%d%n 

 

参考文档如下:

http://www.iteye.com/topic/378077

 

posted @ 2015-02-06 15:43  唾手可得的树  阅读(253)  评论(0编辑  收藏  举报