使用 SMTPAppender 我只收到 ERROR 而不是 INFO 类型的日志项 [英] with SMTPAppender I receive only ERROR and not INFO type of log items

查看:32
本文介绍了使用 SMTPAppender 我只收到 ERROR 而不是 INFO 类型的日志项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的 Java 应用中配置了一个 SMTPAppender.

I've configured an SMTPAppender into my Java app.

<appender name="AdministratorEmail" class="org.apache.log4j.net.SMTPAppender">
  <param name="Threshold" value="info" />
  <param name="BufferSize" value="512" />
  <param name="SMTPHost" value="smtp.sss.intranet" />
  <param name="From" value="adminEbookMaker@sss.intranet" />
  <param name="To" value="user@sss.it" />
  <param name="Subject" value="errors" />       
  <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="[%d{ISO8601}]%n%n%-5p%n%n%c%n%n%m%n%n" />
  </layout>
  <filter class="org.apache.log4j.varia.LevelRangeFilter">
    <param name="LevelMin" value="info" />
    <param name="LevelMax" value="fatal" />
  </filter>
</appender>

我只收到 ERROR 日志类型而不是 INFO 类型!我更改了 LevelMin 但没有,我插入了 Thresold,但没有!

I receive only the ERROR log type and not the INFO type! I changed the LevelMin but nothing, I inserted the Thresold, but nothing!

有人有什么建议吗?

推荐答案

设计的 SMTPAppender 只记录 ERROR 及以上的消息.此级别不受属性影响.附加状态的文档:

The SMTPAppender by design only logs ERROR and above messages. This level cannot be affected by properties. The documentation for the appended states:

默认情况下,当附加 ERROR 或更高严重性的消息时,将发送电子邮件消息.可以通过使用实现 TriggeringEventEvaluator 的类的名称设置 evaluatorClass 属性、使用 TriggeringEventEvaluator 的实例设置 evaluator 属性或在指定类实现 TriggeringEventEvaluator 的位置嵌套 triggeringPolicy 元素来修改触发条件

By default, an email message will be sent when an ERROR or higher severity message is appended. The triggering criteria can be modified by setting the evaluatorClass property with the name of a class implementing TriggeringEventEvaluator, setting the evaluator property with an instance of TriggeringEventEvaluator or nesting a triggeringPolicy element where the specified class implements TriggeringEventEvaluator

请参阅:类 SMTPAppender

您仅在第一个 ERROR 之后才看到 INFO 消息的事实是由于 bufferSize 属性显示了错误之前的n"个最近的日志行,以便为错误提供上下文.

The fact that you are seeing INFO messages only after the first ERROR is due to the bufferSize property which shows the 'n' most recent log lines before the error to give context to the error.

对此的进一步研究表明,在附加伴侣"中存在 TriggerEventEvaluator 所需接口的实现

Further research on this shows that there is an implementation of the required interface for TriggerEventEvaluator in the 'extras companion'

可以从以下位置下载:Apache 下载镜像

如果您将其包含在您的项目中,则可以将以下内容添加到 log4j.xml 中的 SMTPAppender 定义中(注意不支持属性格式!)

If you include this in your project you can then add the following to your SMTPAppender definition in log4j.xml (note the properties format is not supported!)

  <appender name="SMTP" class="org.apache.log4j.net.SMTPAppender">
...
    <triggeringPolicy  class="org.apache.log4j.rolling.FilterBasedTriggeringPolicy">
      <filter class="org.apache.log4j.filter.LevelRangeFilter">
        <param name="levelMin" value="INFO" />
      </filter>
    </triggeringPolicy>
...
  </appender>

这篇关于使用 SMTPAppender 我只收到 ERROR 而不是 INFO 类型的日志项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆