我使用了来自 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".
Bundles 已按顺序加载
.getBundleContext().installBundle("......../log4j-1.2.17.jar")
.getBundleContext().installBundle("......../I_MainForm-1.0-SNAPSHOT.jar")
如何修复此错误?请,对不起我的英语。最好的问候,亚瑟。