我可以在回传中禁用附加程序吗? [英] Can I disable an appender in logback?

查看:61
本文介绍了我可以在回传中禁用附加程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在xml配置上的注销中禁用附加程序吗? 我有我的配置,我想放置两个追加器,一个用于数据库,另一个用于文本日志,但是必须激活一个. 谢谢!

Can I disable an appender in logback on the xml config? I have my configuration and I want to put two appenders, one for database and other for text logs, but only one must be activated. thanks!

推荐答案

不知道为什么要停用附加程序,要禁用该功能是什么?

Not sure why you want to deactivate an appender, what are you trying to achieve by disabling.

有一些方法可以实现它

  1. 在logback.xml中添加附加程序并使其保持注释状态.当你喜欢 启用它,然后取消注释附加程序并重新加载logback 配置 ( http://logback.qos.ch/manual/configuration.html#autoScan)
  2. 添加如下所示的记录器,并使用适当的记录器进行记录
  1. Add the appender in logback.xml and keep it commented. When you like to enable it then uncomment the appender and reload logback configuration (http://logback.qos.ch/manual/configuration.html#autoScan)
  2. Add a logger like the one given below and use appropriate logger for logging

    <configuration>
      <appender name="stdoutappender" />
      <appender name="dbappender" />
      <logger name="stdoutlogger" level="DEBUG">
        <appender-ref ref="stdoutappender" />
      </logger>

      <logger name="dblogger" level="OFF">
        <appender-ref ref="dbappender" />
      </logger>
    </configuration>   

在这种情况下,您还必须在修改logback配置时重新加载配置 (logback.xml)

In this case also you have to reload the configuration when you modify logback configuration (logback.xml)

  1. 如果您事先知道(激活/停用)条件,则使用if else阻止启用/禁用

在上述3个选项之上,您可以通过编程方式创建登录配置

On top of above 3 options you can create logback configurations progamatically

这篇关于我可以在回传中禁用附加程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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