#配置rootLogger (级别+输出源) log4j.rootLogger=debug,A6 #to Console log4j.appender.A=org.apache.log4j.ConsoleAppender log4j.appender.A.layout=org.apache.log4j.SimpleLayout #to Console log4j.appender.A5=org.apache.log4j.ConsoleAppender log4j.appender.A5.layout=org.apache.log4j.PatternLayout log4j.appender.A5.layout.ConversionPattern=[%t] [%p] [%d{yyyy/MM/dd HH:mm:ss:SSS}] %l %m %n #to Console2 TTCCLayout log4j.appender.A3=org.apache.log4j.ConsoleAppender log4j.appender.A3.layout=org.apache.log4j.TTCCLayout #to file1 log4j.appender.A1=org.apache.log4j.FileAppender log4j.appender.A1.File=wepull.log log4j.appender.A1.layout=org.apache.log4j.SimpleLayout #to file2 HTML log4j.appender.A4=org.apache.log4j.FileAppender log4j.appender.A4.File=ht.html log4j.appender.A4.layout=org.apache.log4j.HTMLLayout #to file3 log4j.appender.A6=org.apache.log4j.RollingFileAppender log4j.appender.A6.File=wepull.log log4j.appender.A6.MaxFileSize=2KB log4j.appender.A6.MaxBackupIndex=1 log4j.appender.A6.layout=org.apache.log4j.PatternLayout log4j.appender.A6.layout.ConversionPattern=[%t] [%p] [%d{yyyy/MM/dd HH:mm:ss:SSS}] %l %m %n
package com.wepull.logj4.demo;
import org.apache.log4j.Logger;
public class Test {
public Logger logger = Logger.getLogger(Logger.class.getName());
private void fun() {
logger.error(" this is error msg");
logger.warn(" this is warn msg");
logger.info(" this is info msg");
logger.debug(" this is debug msg");
}
public static void main(String[] args) {
Test d = new Test();
d.fun();
}
}