Log4J使用

### 设置org.zblog域对应的级别INFO,DEBUG,WARN,ERROR和输出地A1,A2 ##
#log4j.category.org.zblog=ERROR,A1
#log4j.category.org.zblog=INFO,A2
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=[%p]-[%c] %d{yyyy-MM-dd HH:mm:ss,SSS}  %m%n
#log4j.rootLogger=DEBUG,A1

#log4j.appender.A2=org.apache.log4j.ConsoleAppender
#log4j.appender.A2.layout=org.apache.log4j.PatternLayout
#log4j.appender.A2.layout.ConversionPattern=[%p]-[%c] %d{yyyy-MM-dd HH:mm:ss,SSS}  %m%n
#log4j.rootLogger=DEBUG,A2


#log4j.logger.java.sql.Connection=DEBUG;
#log4j.logger.java.sql.PreparedStatement=DEBUG;


#### 设置输出地A2到文件(文件大小到达指定尺寸的时候产生一个新的文件)##
log4j.appender.A2=org.apache.log4j.RollingFileAppender
log4j.appender.A2.File=${LOG_DIR}/log4j.log
log4j.appender.A2.MaxFileSize=100
#### 文件大小##
log4j.appender.A2.MaxBackupIndex=10
#log4j.appender.A2.layout=org.apache.log4j.HTMLLayout
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=[%p]-[%c] %d{yyyy-MM-dd HH:mm:ss,SSS}  %m%n

log4j.logger.log4j=DEBUG, A1, A2
log4j.category.ontime=DEBUG, A1, A2

===================================================
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package log4j;

import org.apache.log4j.Logger;

/**
*
* @author bg
*/
public class Log4jTest
{
    public static void main(String[] args)
    {
        System.setProperty("LOG_DIR", "E:/log");
       
        Logger logger = Logger.getLogger(Log4jTest.class);
        logger.error("第一段信息");       
    }
   
}

你可能感兴趣的:(log4j)