我从Maven的回购使用Log4j-1.2.17包。 我尝试在束做到这一点代码(我的包调用log4j的-1.2.17包)
PropertyConfigurator.configure(props());
private static Properties props() {
Properties props = new Properties();
props.put("log4j.rootLogger", "INFO, R");
props.put("log4j.appender.R",
"org.apache.log4j.DailyRollingFileAppender");
props.put("log4j.appender.R.File", "logs/IhtikaClient.log");
props.put("log4j.appender.R.Append", "true");
props.put("log4j.appender.R.Threshold", "INFO");
props.put("log4j.appender.R.DatePattern", "'.'yyyy-MM-dd");
props.put("log4j.appender.R.layout", "org.apache.log4j.PatternLayout");
props.put("log4j.appender.R.layout.ConversionPattern",
//"%d{HH:mm:ss,SSS} %c - %m%n");
//"[%5p] %d{yyyy-MM-dd mm:ss} (%F:%M:%L)%n%m%n%n");
"[%5p] %d{yyyy-MM-dd mm:ss} %c (%F:%M:%L)%n%m%n");
return props;
}
但我有错误
log4j:ERROR A "org.apache.log4j.DailyRollingFileAppender" object is not assignable to a "org.apache.log4j.Appender" variable. log4j:ERROR The class "org.apache.log4j.Appender" was loaded by log4j:ERROR [org.apache.felix.framework.BundleWiringImpl@9da1dd] whereas object of type log4j:ERROR "org.apache.log4j.DailyRollingFileAppender" was loaded by [sun.misc.Launcher$AppClassLoader@4b222f]. log4j:ERROR Could not instantiate appender named "R". log4j:ERROR A "org.apache.log4j.DailyRollingFileAppender" object is not assignable to a "org.apache.log4j.Appender" variable. log4j:ERROR The class "org.apache.log4j.Appender" was loaded by log4j:ERROR [org.apache.felix.framework.BundleWiringImpl@9da1dd] whereas object of type log4j:ERROR "org.apache.log4j.DailyRollingFileAppender" was loaded by [sun.misc.Launcher$AppClassLoader@4b222f]. log4j:ERROR Could not instantiate appender named "R".
包加载顺序
.getBundleContext().installBundle("......../log4j-1.2.17.jar")
.getBundleContext().installBundle("......../I_MainForm-1.0-SNAPSHOT.jar")
如何解决这个问题? 请,对不起我的英语。 最好的问候,亚瑟。