Java 如何关闭 slf4j 的日志记录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2372056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 06:39:23  来源:igfitidea点击:

How to turn off logging from slf4j

javaloggingjakarta-eeslf4j

提问by Tommy

It's a third party application generating huge amounts of logentries on our appserver. Like this:

它是在我们的应用程序服务器上生成大量日志的第三方应用程序。像这样:

[03.03.10 15:21:57:250 CET] 00000180 FtpProtocolHa I org.slf4j.impl.JCLLoggerAdapter info Close connection : 10.227.10.10 - admin
[03.03.10 15:27:35:209 CET] 00000181 MinaFtpProtoc I org.slf4j.impl.JCLLoggerAdapter info [/10.227.10.10] CLOSED
++++

How do I turn this output from slf4j off? I've looked in the .war-file to find some configuration for slf4j but nothing. Their website didn't help either

如何关闭 slf4j 的此输出?我查看了 .war 文件以找到 slf4j 的一些配置,但什么也没有。他们的网站也没有帮助

采纳答案by Thorbj?rn Ravn Andersen

slf4j is just a funnel to the actual log backend (here overriding jakarta commons logging), which is the one you must configure to get rid of a certain kind of messages. For logback this is the appropriate configuration snippet:

slf4j 只是实际日志后端(此处覆盖 jakarta commons 日志记录)的一个漏斗,这是您必须配置以摆脱某种消息的漏斗。对于 logback,这是适当的配置片段:

    <!--  No Tomcat debug logs -->
    <configuration>
    ...
        <logger name="org.apache.catalina.core" level="OFF" />
    ...
    </configuration>

For log4j it is very similar.

对于 log4j,它非常相似。

回答by rodrigoap

slf4j is a logging facade for various logging frameworks. That output comes from the Apache Commons Loggin framework adapter, that turns to be another facade. Commons Logging Configuration.

slf4j 是各种日志框架的日志外观。该输出来自 Apache Commons Loggin 框架适配器,它变成了另一个外观。公共日志配置

回答by Ceki

Which logging back-end, e.g. logback, log4j, j.u.l., are you using? You need to configure the backend to filter those messages.

您使用的是哪个日志记录后端,例如 logback、log4j、jul?您需要配置后端来过滤这些消息。

Moreover, the fact that the log messages point to "org.slf4j.impl.JCLLoggerAdapter" indicates that caller location inference is notworking correctly. (It should mention the actual caller not JCLLoggerAdapter). This can happen if:

此外,日志消息指向“ org.slf4j.impl.JCLLoggerAdapter”这一事实表明调用方位置推断正常工作。(它应该提到实际的调用者而不是JCLLoggerAdapter)。在以下情况下可能会发生这种情况:

  1. you are using an older version of SLF4J
  1. 您使用的是旧版本的 SLF4J

or

或者

  1. the caller is using a slf4j-like wrapper or has its own homegrown logging API which does not infer caller location properly. See also a relevant SLF4J FAQ entry.
  1. 调用者正在使用类似 slf4j 的包装器或拥有自己的本地日志 API,该 API 无法正确推断调用者位置。另请参阅相关的SLF4J 常见问题条目

回答by sparkyspider

Alternatively, download http://www.slf4j.org/dist/slf4j-1.6.4.tar.gz, look in there for slf4j-nop-1.6.4.jar (this is the no-operation logger) and include this in your classpath. When the SLF4J classloader sees this (it looks to see what loggers are in the classpath that it can use), it shouldstop logging (once you've restarted the app).

或者,下载http://www.slf4j.org/dist/slf4j-1.6.4.tar.gz,在那里寻找 slf4j-nop-1.6.4.jar(这是无操作记录器)并包含这个在你的类路径中。当 SLF4J 类加载器看到这一点时(它会查看它可以使用的类路径中的记录器),它应该停止记录(一旦你重新启动了应用程序)。

At least this way you don't need to mess with the log configuration files...

至少这样你就不需要弄乱日志配置文件......

回答by ROMANIA_engineer

Search for the following string: level="DEBUG"using your IDE. You will find that text in a .xmlfile.

搜索以下字符串:level="DEBUG"using your IDE。您将在.xml文件中找到该文本。

Go there and use level="INFO"instead of level="DEBUG".

去那里使用level="INFO"而不是level="DEBUG".

The key value is not case-sensitive.

键值不区分大小写。

There can be something like:

可能有这样的事情:

<root level="info">
    ...
</root>