How to turn off logging from SLF4J?
Asked Answered
R

7

23

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.

Rozalin answered 3/3, 2010 at 14:31 Comment(0)
I
17

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 which goes in your logback.xml configuration file:

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

For log4j it is very similar.

Imperishable answered 5/3, 2010 at 12:36 Comment(1)
Where is this snippet supposed to go?Intermezzo
P
15

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...

Piper answered 5/1, 2012 at 19:27 Comment(3)
On my system I had to also remove slf4j-log4j*.jar from my classpath.Hematite
slf4j will dislike intensely if you have more than one slf4j backend in the classpath.Kerley
I am using maven, I added the dependency that Mr Zorn suggested, I changed other slf4j dependencies to all have the same version, as Thorbjørn Ravn Andersen suggested, but I am still seeing the logs from the external library.Westcott
N
4

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")
}
Notorious answered 25/4, 2022 at 7:15 Comment(0)
W
3

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.

Winn answered 3/3, 2010 at 15:12 Comment(0)
M
3

Which logging back-end, e.g. logback, log4j, j.u.l., 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.
Mayhew answered 5/3, 2010 at 12:10 Comment(1)
This is a third party application. I don't have access to any code (other than decompiling) There are no log4j.properties files or any other files that look like they containt any log-propertiesRozalin
A
0

I will tell about a special case.

I was working on a simple discardable prototype (using easy-rules) which had a sfl4j dependency.

I get an error telling me wich some providers were not provided, and i have to add another dependency.

I add such dependency in pom.xml and get the logging working.

But still the «SLF4J(I): Connected with provider of type [org.slf4j.simple.SimpleServiceProvider]» was appearing (which I didn't wanted to appear).

At the end, I came to the slf4j-api-xxx.jar and I found that the verbosity was caused because a java system property "slf4j.internal.verbosity".

After a time I figured out that the only thing I could do is disabling it by:

System.setProperty("slf4j.internal.verbosity", "WARN") //Because it defaults to INFO.

Finally, because I had written a «simplelogger.properties» file:

org.slf4j.simpleLogger.defaultLogLevel=info

slf4j.internal.verbosity=WARN

I decided to use such file in my main method this way:

public static void main(String[] args) throws Exception {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    hideLoggingProviderData(classLoader);
    ...
}

private static void hideLoggingProviderData(ClassLoader classLoader) throws IOException {
    Properties loggingProperties = new Properties();
    loggingProperties.load(classLoader.getResourceAsStream("simplelogger.properties"));
    Object obj = loggingProperties.get("slf4j.internal.verbosity");
    if (obj!=null) {
        System.setProperty("slf4j.internal.verbosity", obj.toString());
    }
}

And then I get ride off that (for me) useless message.

Andrews answered 22/4, 2024 at 12:50 Comment(0)
S
-1

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>
Selfconsequence answered 21/8, 2014 at 7:21 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.