属性文件中的 log4j StringToMatch

发布于 2024-09-24 02:45:29 字数 3303 浏览 6 评论 0原文

我有以下 XML 配置,我想转换为 java 属性文件。

我收到以下错误:

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 配置

  <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 并指定

I have following XML configration i would like to convert to java property file.

I am getting below error

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)

My 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"/>

After converting the property file is as below. With XML configration it is working fine.

Property File

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

Please let me know how i can use StringToMatch in property file and specify

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

霓裳挽歌倾城醉 2024-10-01 02:45:29
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d %-6p [%c] %m%n
log4j.appender.console.filter.1=org.apache.log4j.varia.StringMatchFilter
log4j.appender.console.filter.1.StringToMatch=entered
log4j.appender.console.filter.1.AcceptOnMatch=true
log4j.appender.console.filter.2=org.apache.log4j.varia.DenyAllFilter

确实有效

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d %-6p [%c] %m%n
log4j.appender.console.filter.1=org.apache.log4j.varia.StringMatchFilter
log4j.appender.console.filter.1.StringToMatch=entered
log4j.appender.console.filter.1.AcceptOnMatch=true
log4j.appender.console.filter.2=org.apache.log4j.varia.DenyAllFilter

does work

勿忘心安 2024-10-01 02:45:29

属性文件不支持过滤器。您必须切换到 XML 配置。

来自 Filter 的文档:

请注意,仅 DOMConfiguratorPropertyConfigurator 不支持过滤器。


资源:

同一主题:

Properties files don't support filters. You'll have to switch to an XML configuration.

From the documentation of Filter :

Note that filtering is only supported by the DOMConfigurator. The PropertyConfigurator does not support filters.


Resources :

On the same topic :

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文