Reputation: 618
I have used SLF4J logging to print all the logs. I am using the latest version of org.slf4j.
implementation 'org.slf4j:slf4j-api:2.0.0-alpha1'
implementation 'org.slf4j:log4j-over-slf4j:2.0.0-alpha1'
But I'm getting the following error and also no logs are being printed.
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.
SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions prior to 1.8.
SLF4J: Ignoring binding found at [jar:file:/home/user/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.3/7c4f3c474fb2c041d8028740440937705ebb473a/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#ignoredBindings for an explanation.
The logs are working fine with the older version (1.7.25). Is there anything needs to be added or configured on the project so that these logs can be printed
Upvotes: 14
Views: 6535
Reputation: 3383
You don't need to import any log dependency when using Spring Boot 2.x. All that is required is to import some Spring Boot Starter, which you most likely have already done. E.g. spring-boot-starter-web
, which depends on spring-boot-starter-logging
, which pulls in spring-jcl
module required for logging with Spring Framework.
When using starters, Logback is used for logging by default, Log4j is not required.
Just remove all references to slf4j
from your build file. Here is how the reference to Spring Boot Web Starter looks like in the build.gradle file.
compile("org.springframework.boot:spring-boot-starter-web")
Upvotes: 1
Reputation: 2144
It will print the messages adding slf4j-log4j12 instead of slf4j-api
Remove the following
implementation 'org.slf4j:slf4j-api:2.0.0-alpha1'
implementation 'org.slf4j:log4j-over-slf4j:2.0.0-alpha1'
Add
implementation group: 'org.slf4j', name: 'slf4j-log4j12', version: '+'
Upvotes: 2
Reputation: 83
This is because slf4j is an abstraction that needs binding with other pre-existing libraries. Hence, if you're using simply slf4j to print logs, it wouldn't work because it wouldn't have the settings on logging levels etc. This link gives some information on the same.
Also, Spring Boot's new version has a default integration with slf4j for version 1.7.9
Upvotes: 0