slf4j,logback-引用未从任何记录器引用的追加器 [英] slf4j, logback - refer to appender that is not referenced from any logger

查看:103
本文介绍了slf4j,logback-引用未从任何记录器引用的追加器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在logger.xml文件中定义SMTPAppender,但是我不想从任何记录器中引用它.

I want to define SMTPAppender in the logger.xml file, but I do not wish to reference it from any logger.

然后,在我的应用程序加载时,我希望以编程方式将此附加程序添加到特定的记录器中.

Then when my application loads, I wish to programmatically add this appender to specific loggers.

但是只能从Logger访问"getAppender"方法.

However the "getAppender" method is accessible only from Logger.

是否有解决此问题的方法,并且无需通过任何记录器即可获取附加器?

Is there a way to work around this and get the appender without going through any logger?

推荐答案

是的!绝对可以这样做,但是发送每个关卡事件可能会导致电子邮件过多,使目标用户的邮箱混乱,并且还会影响您的表现.

Yes!!! absolutely you can do that but sending every event of level may result in too many emails, cluttering the targeted user's mailbox and it also hamper your performances.

以下是完成任务的步骤:

Here are the steps by which you can achieve your task :

第1步:将janino jar添加到您的类路径中,您可以在此处下载 http://janino.net/changelog. html

Step 1: Add janino jars into your classpath, you can download here http://janino.net/changelog.html

第2步:在SMTPAppender中添加以下评估程序:

Step 2: Add following evaluator in your SMTPAppender:

<evaluator  class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">
  <expression>
     (marker == null) 
  </expression>
</evaluator>

这篇关于slf4j,logback-引用未从任何记录器引用的追加器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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