如何确定Logback实际使用的日志配置源? [英] How can I determine what log configuration source Logback actually used?

查看:77
本文介绍了如何确定Logback实际使用的日志配置源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

log4j有一个属性 log4j.debug ,这将有助于向用户提供实际用于配置日志记录系统的配置文件的指示。

log4j has a property, log4j.debug, which will helpfully provide the user with an indication of which configuration file was actually used to configure the logging system.

我无法找到与(否则更优越的)Logback日志框架等效的东西。有没有办法在运行时打印(用于诊断目的),哪个配置文件Logback用于自举?

I haven't been able to find anything equivalent with the (otherwise superior) Logback logging framework. Is there any way to print (for diagnostic purposes) at runtime, which configuration file Logback used to bootstrap itself?

[edit]
为了澄清,我'理想情况下,像一个不需要我修改配置文件本身的解决方案(例如,由于错误组装的第三方JAR可能被错误地拾取,并且在我的回溯配置XML之前)。

[edit] To clarify, I'd ideally like a solution that doesn't require me to modify the configuration file itself (since a badly assembled third-party JAR, for example, may be picked up incorrectly, and prior to my logback configuration XML).

推荐答案

您可以设置Java系统属性以输出Logback调试信息:

You can set a Java system property to output Logback debugging info:

java -Dlogback.statusListenerClass=ch.qos.logback.core.status.OnConsoleStatusListener

自动状态打印的Logback文档进一步说明了这一点(非常底部)提到强制状态输出)和 logback.statusListenerClass属性

This is further explained by the Logback documentation for automatic status printing (very bottom mentions forcing status output) and the logback.statusListenerClass property:


在没有状态消息的情况下,追踪流氓logback.xml配置文件可能很困难,尤其是在生产中应用程序源无法轻易修改。要帮助识别恶意配置文件的位置,可以通过logback.statusListenerClass系统属性(在下面定义)设置StatusListener以强制输出状态消息。 logback.statusListenerClass系统属性也可用于静音在出错时自动生成的输出。

In the absence of status messages, tracking down a rogue logback.xml configuration file can be difficult, especially in production where the application source cannot be easily modified. To help identify the location of a rogue configuration file, you can set a StatusListener via the "logback.statusListenerClass" system property (defined below) to force output of status messages. The "logback.statusListenerClass" system property can also be used to silence output automatically generated in case of errors.

这篇关于如何确定Logback实际使用的日志配置源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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