日期:2014-05-19  浏览次数:20725 次

log4j问题
配置文件
Java code

log4j.rootCategory=INFO, stdout , R

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.R=org.apache.log4j.RollingFileAppender   
log4j.appender.R.File=d\:/batchprocessdata/log.log 
#log4j.appender.R.DatePattern = '.'yyyy-MM-dd  
log4j.appender.R.Append=true    
log4j.appender.R.MaxFileSize=4MB    
log4j.appender.R.MaxBackupIndex=1000    
log4j.appender.R.layout=org.apache.log4j.PatternLayout 
log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd } [%c]-[%p] %m%n 
log4j.logger.org.springframework=DEBUG

log4j.logger.org.hibernate=DEBUG

log4j.logger.org.hibernate.ps.PreparedStatementCache=DEBUG

log4j.logger.com.myproject=DEBUG



Java code

import java.util.logging.Logger;
import java.util.regex.Pattern;

public class tt {
    private static final Logger LOG = Logger.getLogger(tt .class.getName());
    public static void main(String[] args) {

        PropertyConfigurator.configure("log4j.properties");
        LOG.info("sdfsdfasdf");
        LOG.info("sdfsdfasdf");
         }
    }


能在指定文件夹下面建立log文件,但是就是内容就是没有被记录在log中。

------解决方案--------------------
import org.apache.log4j.Logger;
import java.util.regex.Pattern;

public class tt {
private static final Logger LOG = Logger.getLogger(tt .class.getName());
public static void main(String[] args) {

// PropertyConfigurator.configure("log4j.properties");
LOG.info("sdfsdfasdf");
LOG.info("sdfsdfasdf");
}
}