pom.xml
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
log4j.properties
log4j.rootLogger=INFO,log
log4j.appender.log = org.apache.log4j.RollingFileAppender
log4j.appender.log.layout = org.apache.log4j.PatternLayout
log4j.appender.log.layout.ConversionPattern = [%-5p][%-22d{yyyy/MM/dd HH:mm:ssS}][%l]%n%m%n
log4j.appender.log.Threshold = INFO
log4j.appender.log.ImmediateFlush = TRUE
log4j.appender.log.Append = TRUE
log4j.appender.log.File = G:/temp/access.log
#log4j.appender.log.File = /root/hello/access.log
log4j.appender.log.MaxFileSize = 10KB
log4j.appender.log.MaxBackupIndex = 20
LogGenerator.java
package com.fengqing;
import org.apache.log4j.Logger;
import java.util.Date;
public class LogGenerator {
public static void main(String[] args) throws Exception{
Logger logger = Logger.getLogger(LogGenerator.class);
for (int i = 1; i <= 500; i++) {
logger.info("==>" + new Date().toString());
Thread.sleep(500);
}
}
}