我有以下XML配置我想轉換爲java屬性文件。log4j屬性文件中的StringToMatch
我得到以下錯誤
log4j:WARN Failed to set property [filter] to value "org.apache.log4j.varia.DenyAllFilter".
log4j:ERROR Could not instantiate class [true].
java.lang.ClassNotFoundException: true
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.apache.log4j.helpers.Loader.loadClass(Loader.java:198)
at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:326)
at org.apache.log4j.PropertyConfigurator.parseAppenderFilters(PropertyConfigurator.java:881)
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:812)
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:735)
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:615)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:502)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:395)
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:403)
at simpandfile.main(simpandfile.java:10)
我的XML CONFIGRATION
<filter class="org.apache.log4j.varia.StringMatchFilter">
<param name="StringToMatch" value="FileNotfound" />
<param name="AcceptOnMatch" value="true" />
</filter>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="ERROR"/>
<param name="LevelMax" value="FATAL"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"/>
轉換屬性文件後,如下圖所示。使用XML配置它工作正常。
屬性文件
log4j.rootLogger=INFO, MAIL
log4j.appender.MAIL=org.apache.log4j.net.SMTPAppender
# here's where I specify the layout and the pattern
log4j.appender.MAIL.BufferSize=1
log4j.appender.MAIL.SMTPHost=xxx.example.com
[email protected]
[email protected]
log4j.appender.MAIL.Subject=Test Email.
log4j.appender.MAIL.threshold=error
log4j.appender.MAIL.layout=org.apache.log4j.PatternLayout
log4j.appender.MAIL.layout.ConversionPattern=[%d{ISO8601}]%n%n%-5p%n%n%c%n%n%m%n%n
log4j.appender.MAIL.filter=org.apache.log4j.varia.StringMatchFilter
log4j.appender.MAIL.filter.StringToMatch=Filenotfound
log4j.appender.MAIL.filter.AcceptOnMatch=true
log4j.appender.MAIL.filter=org.apache.log4j.varia.DenyAllFilter
log4j.logger.com.devdaily.myapp=DEBUG
log4j.logger.org.springframework=DEBUG
請讓我知道我可以在屬性文件中使用StringToMatch並指定
語法用於添加到過濾器一個appender是:log4j.appender.appenderName.filter.ID = fully.qualified.name.of.filter.class log4j.appender。 appenderName.filter.ID.option1 = value1 ... log4j.appender.appenderName.filter.ID.optionN = valueN我在上面發送的鏈接中看到了這個。我不是很確定這個 – user171523 2010-09-16 22:06:41
這個答案是不對的 – 2011-11-15 08:47:42
答案是正確的...我測試了1.2.15,1.2.16,1.2.17和PropertyConfigurator沒有用於過濾器...我讀了你的下面的評論( 「它工作。1.2.16 - Jan Zyka 11月15日11點8:48」)...但這不是真的@JanZyka。你能分享你的配置嗎? – Aykut 2012-09-04 13:20:13