Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable logging in org.slf4j for the version: '2.0.0-alpha1' in Spring boot

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

like image 236
r123 Avatar asked Apr 17 '20 08:04

r123


People also ask

Which version of log4j is used in SLF4J?

As the name already indicates slf4j-log4j12 contains log4j v1. 2.

Is SLF4J included in spring boot?

Spring Boot makes use of Apache Commons' Logging for its system logs by default. Additionally, by default you can use any of the logging frameworks under the SLF4J API such as Logback (which is the default), Log4J2, and Java Util Logging in Spring Boot.

Which Logger is used by SLF4J?

SLF4J supports popular logging frameworks, namely log4j, java. util. logging, Simple logging and NOP. The logback project supports SLF4J natively.

What is SLF4J version?

Simple Logging Facade for Java (SLF4J) provides a Java logging API by means of a simple facade pattern. The underlying logging backend is determined at runtime by adding the desired binding to the classpath and may be the standard Sun Java logging package java.


1 Answers

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: '+'
like image 111
SST Avatar answered Oct 18 '22 07:10

SST