从 log4j 发送电子邮件
我目前通过 log4j 通过电子邮件发送错误记录:
<appender name="email" class="org.apache.log4j.net.SMTPAppender">
<param name="SMTPHost" value="localhost"/>
<param name="From" value="[email protected]"/>
<param name="To" value="[email protected]"/>
<param name="Subject" value="Error from mydomain.com"/>
</appender>
效果很好,但我真的很想偶尔从特定的日志文件向我发送电子邮件。对于另一个日志文件,我什至还想要记录的 INFO 事件。我该怎么做?如果我尝试设置另一个 emailAppender,或者只是使用这个 emailAppender,则不会通过电子邮件发送任何内容,因为似乎有一个针对错误或更糟糕事件的过滤器。所以我尝试添加 LevelRangeFilter:
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="INFO"/>
<param name="LevelMax" value="FATAL"/>
</filter>
但它对 SMTPAppender 没有影响:(。
I currently email errors logged through log4j with:
<appender name="email" class="org.apache.log4j.net.SMTPAppender">
<param name="SMTPHost" value="localhost"/>
<param name="From" value="[email protected]"/>
<param name="To" value="[email protected]"/>
<param name="Subject" value="Error from mydomain.com"/>
</appender>
works great, but I'd really like to email me occasionally from a particular log file. This other log file, I also want even the INFO events that are logged. How do I do that? If I try to setup another emailAppender, or just use this emailAppender, nothing gets emailed because there seems to be a filter on ERROR or worse events. So I tried adding a LevelRangeFilter:
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="INFO"/>
<param name="LevelMax" value="FATAL"/>
</filter>
But it has no effect on an SMTPAppender :(.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 javadoc 看起来像这样appender 使用一个超级特殊的 TriggeringEventEvaluator 作为过滤机制。您可以通过使用始终返回 true 的求值器创建附加程序来解决此问题。但我不确定。
From the javadoc it looks like this appender uses a super special TriggeringEventEvaluator as a filtering mechanism. You can probably fix this by creating your appender with an evaluator that always returns true. I'm not sure though.