禁止所有 Logback 输出到控制台? [英] Suppress all Logback output to console?

查看:59
本文介绍了禁止所有 Logback 输出到控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何配置 Logback 以抑制其所有输出到控制台(标准输出)?特别是,我希望抑制(或重定向)Logback 自己的日志消息,例如:

How can I configure Logback to suppress all of its output to the console (standard output)? In particular, I wish to suppress (or redirect) Logback's own log messages such as the following:

16:50:25,814 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
16:50:25,814 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/opt/dap/domains/ap0491/uat1/domain/instance-config/logback.xml]
16:50:25,816 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs multiple times on the classpath.
16:50:25,816 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [file:/opt/dap/domains/ap0491/uat1/domain/instance-config/logback.xml]
16:50:25,816 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [file:/opt/dap/domains/ap0491/uat1/domain/instance-config/logback.xml]
16:50:25,923 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
16:50:25,924 |-INFO in ch.qos.logback.classic.turbo.ReconfigureOnChangeFilter@1a15291 - Will scan for changes in file [/opt/dap/domains/ap0491/uat1/domain/instance-config/logback.xml] every 60 seconds. 

我需要禁用所有记录到标准输出的功能,因为我们的生产环境不允许应用程序将任何消息打印到标准输出.

I need to disable all logging to standard output because our production environment disallows applications from printing any messages to standard output.

注意我使用的是 Logback 0.9.21、SLF4J 1.6.0,我们的应用程序在 WebLogic 10.3.2 中运行.

Note I'm using Logback 0.9.21, SLF4J 1.6.0, and our application runs in WebLogic 10.3.2.

推荐答案

Holger Hoffstätte 在他的 诊断 重复的类路径条目消息是 bug Logback 如何计算类路径条目.Robert Elliot 还表征线程 在 Logback 用户邮件列表.根据罗伯特和其他人在 SLF4J 邮件列表上的相关讨论中的说法,当使用 Logback 的应用程序在 WebLogic 容器中运行,由于 WebLogic 类加载器的运行方式,Logback 会报告 logback.xml 配置文件的重复类路径条目.然而,无论 WebLogic 类加载器是否应该或不应该只报告唯一的类路径条目,Logback 肯定应该只计算唯一的类路径条目,这样它就不会打印出这种令人困惑、虚假的消息.

Holger Hoffstätte was correct in his diagnosis that the duplicate classpath entry message is a symptom of a bug in how Logback counts classpath entries. Robert Elliot also characterized the problem in a thread on the Logback user mailing list. According to Robert and others in this related disussion on the SLF4J mailing list, when an application that uses Logback runs in a WebLogic container, due to the way the WebLogic classloader operates, Logback reports duplicate classpath entries for the logback.xml configuration file. However, regardless of whether the WebLogic classloader should or should not report only unique classpath entries, Logback should certainly count only unique classpath entries so that it does not print this confusing, spurious message.

我已经为 LBCLASSIC-159 本质上按照 Robert Elliot 的建议执行并使用集合而不是列表来保存类加载器返回的资源,有效地消除任何重复的类路径资源.我已经使用 Logback 0.9.24、SLF4J 1.6.1 和 WebLogic 10.3.2 成功测试了该修复程序.正如 Thorbjørn 在他的 answer 中预测的那样,有了这个修复程序, Logback 不再向标准输出显示重复的类路径条目状态消息(或任何其他信息性消息).

I have implemented a fix for LBCLASSIC-159 that essentially does what Robert Elliot recommends and uses a set instead of a list to hold the resources that the classloader returns, effectively eliminating any duplicate classpath resources. I have successfully tested the fix with Logback 0.9.24, SLF4J 1.6.1, and WebLogic 10.3.2. As Thorbjørn predicted in his answer, with this fix in place, Logback no longer displays the duplicate classpath entry status messages (or any of the other informational messages) to standard output.

我希望维护者将我的修复程序集成到主 Logback 源代码存储库和将其包含在下一个版本中.

I hope that the maintainers will integrate my fix into the main Logback source code repository and include it in the next release.

这篇关于禁止所有 Logback 输出到控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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