2
我有使用log4j與文件記錄問題。即使在網上搜索很長一段時間後,我也無法使其工作。Log4j FileAppender創建空文件
我log4j.properties文件:
log4j.rootLogger = DEBUG, FILE
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=log.out
log4j.appender.FILE.ImmediateFlush=true
log4j.appender.FILE.Append=true
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n
我的Java類生產:
@Singleton
public class Loggers {
@Produces
public Logger getLogger(InjectionPoint ip) throws IOException {
Member member = ip.getMember();
Class<?> declaredInClass=member.getDeclaringClass();
Logger logger=Logger.getLogger(declaredInClass.getSimpleName());
Properties props = new Properties();
props.load(Loggers.class.getClassLoader().getResourceAsStream(("log4j.properties")));
PropertyConfigurator.configure(props);
logger.info("should be in the file but it is only in console");
return logger;
}
}
什麼可能性,它只是創建空文件,並不會記錄呢?但是,它會記錄到控制檯。