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

查看:2262
本文介绍了抑制所有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.

推荐答案

HolgerHoffstätte在他的诊断重复的类路径条目消息是 bug 如何Logback如何计数类路径条目。 Robert Elliot还描述了 =http://www.qos.ch/pipermail/logback-user/2010-August/001716.html =nofollow noreferrer>线索在日志用户邮寄名单。根据Robert和其他人在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.

我对修复 jira.qos.ch/browse/LBCLASSIC-159rel =nofollow noreferrer> LBCLASSIC-159 本质上是由Robert Elliot推荐的,并使用一个集合而不是列表来保存类加载器返回的资源,有效地消除任何重复的类路径资源。我已成功测试与Logback 0.9.24,SLF4J 1.6.1和WebLogic 10.3.2的修复。正如Thorbjørn在他的回答中所预测的, ,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天全站免登陆