简体   繁体   中英

How to turn off logging from SLF4J?

It's a third party application generating huge amounts of log entries on our app server. 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.

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 should stop logging (once you've restarted the app).

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

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:

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

For log4j it is very similar.

Which logging back-end, eg logback, log4j, jul, are you using? You need to configure the backend to filter those messages.

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

  1. you are using an older version of 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 .

As stated by @sparkyspider answer , you can simply add the slf4j-nop library to your application.

If using Maven, add this to your pom.xml file:

<dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-nop</artifactId>
        <version>1.7.36</version>
    </dependency> 
</dependencies>

If using Gradle, add this to your build.gradle[.kts] file:

dependencies {
    implementation("org.slf4j:slf4j-nop:1.7.36")
}

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 .

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

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

The key value is not case-sensitive.

There can be something like:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM