No SLF4J providers were found - java

Have two dependencies added to my project
enter image description here via Maven.
However, I see that org.slf4j:slf4j-simple:2.0.6 is not added (at least from IntelliJ log I understand so).
IntelliJ console output:
/Library/Java/JavaVirtualMachines/jdk-17.0.5.jdk/Contents/Home/bin/java -javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=56496:/Applications/IntelliJ IDEA CE.app/Contents/bin -Dfile.encoding=UTF-8
-classpath /Users/arturaspaluskinas/Documents/JavaRushTasks/out/production/4.JavaCollections:/Users/arturaspaluskinas/.m2/repository/junit/junit/4.13.1/junit-4.13.1.jar:/Users/arturaspaluskinas/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:/Users/arturaspaluskinas/.m2/repository/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar:/Users/arturaspaluskinas/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar:/Users/arturaspaluskinas/.m2/repository/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar:/Users/arturaspaluskinas/.m2/repository/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar:/Users/arturaspaluskinas/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:/Users/arturaspaluskinas/.m2/repository/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar:/Users/arturaspaluskinas/.m2/repository/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar:/Users/arturaspaluskinas/.m2/repository/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar:/Users/arturaspaluskinas/.m2/repository/javax/xml/bind/jaxb-api/2.3.1/jaxb-api-2.3.1.jar:/Users/arturaspaluskinas/.m2/repository/org/slf4j/slf4j-api/2.0.6/slf4j-api-2.0.6.jar com.javarush.task.MyLogger
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
documentation https://www.slf4j.org/codes.html says that adding one of slf4j-nop.jar slf4j-simple.jar, slf4j-reload4j.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.
Any ideas why Java or IDEA cannot find slf4j ?

use the below dependency:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.6</version>
</dependency>
and keep the log4j.properties file in src/main/resources.
a sample file for printing the log in the console.:
log4j.rootLogger=debug,console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d [%t] %-5p %L - %m%n

Related

Build failing when including the Openshift Java RESTClient

I have a project using Spring, and as soon as I include the below in my pom.xml file:
<dependency>
<groupId>com.openshift</groupId>
<artifactId>openshift-restclient-java</artifactId>
<version>6.1.3.Final</version>
</dependency>
I get the below set of errors. Any ideas on how to fix this?
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/m/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/m/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
The Class-Path manifest attribute in /Users/m/.m2/repository/org/liquibase/liquibase-core/3.5.5/liquibase-core-3.5.5.jar referenced one or more files that do not exist: file:/Users/m/.m2/repository/org/liquibase/liquibase-core/3.5.5/lib/snakeyaml-1.13.jar
log4j:WARN No appenders could be found for logger (org.springframework.boot.devtools.settings.DevToolsSettings).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from file:/Users/m/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory
at org.springframework.util.Assert.instanceCheckFailed(Assert.java:637)
at org.springframework.util.Assert.isInstanceOf(Assert.java:537)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:286)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:102)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:191)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:170)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:68)
at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:319)
at com.g2.automationstation.AutomationstationApp.main(AutomationstationApp.java:63)
... 5 more
Both Spring boot and the Openshift library use slf4j, which is a logging bridge framework. However, they both include a different bindings:
Spring boot includes Logbback
Openshift includes log4j
You can fix this by excluding either one of them, for example:
<!-- language: lang-xml -->
<dependency>
<groupId>com.openshift</groupId>
<artifactId>openshift-restclient-java</artifactId>
<version>6.1.3.Final</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>

Java log: failed to load slf4j but I'm using log4j2. How to fix?

When I run my jar file, I get the following error:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
The problem is that I'm not using slf4j, I'm using log4j2. It is used by a dependency. Maven correctly includes org.slf4j:slf4j-api as a transitive dependency of a library that I'm using.
How do I get rid of this warning? I do not even want to log problems with this dependency.
I've solved it with this dependency:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.11.0</version>
</dependency>
This will add the log4j2 as the implementation of slf4j api. I can even display log events of the dependency if I want.

How to enable Kafka logging with log4j

I downloaded kafka-clients-0.9.0.0.jar with maven and i expect i would see logging like those in this link Kafka Logging
However i have no idea why i am not getting any logging, even I set the bootstrap.servers wrongly on purpuse, but it just got stuck without throwing any warning.
I added a few lines of code to print to a file using log4j and it seems work but no idea why Kafka cannot log event to log4j.
import org.apache.log4j.Logger;
public class ConsumerLoop implements Runnable {
final static Logger logger = Logger.getLogger(ConsumerLoop.class);
#Override
public void run() {
logger.warn("running!!!!!");
}
}
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2016-04-04 12:54:01 WARN ConsumerLoop:40 - running!!!!!
Note, there is slf4j-api-1.7.6.jar that came as a dependency of kafka. Even I included the required library slf4j-api-x.x.x.jar, slf4j-log4jx-x.x.x.jar and used slf4j to log even but still cannot get the kafka logs.
This is an old question but someone may still benefit.
Just put log4j.properties under /src/main/resources with data
log4j.rootLogger=TRACE, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%c)%n
#log4j.appender.fileAppender=org.apache.log4j.FileAppender
#log4j.appender.fileAppender.File=kafka-request.log
#log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
#log4j.appender.fileAppender.layout.ConversionPattern= %-4r [%t] %-5p %c %x - %m%n
# Turn on all our debugging info
log4j.logger.kafka=TRACE,stdout
#log4j.logger.kafka.producer.async.DefaultEventHandler=DEBUG,stdout
#log4j.logger.kafka.consumer.PartitionTopicInfo=TRACE,stdout
#log4j.logger.kafka.request.logger=TRACE,fileAppender
#log4j.additivity.kafka.request.logger=false
#log4j.logger.kafka.network.Processor=TRACE,fileAppender
#log4j.additivity.kafka.network.Processor=false
#log4j.logger.org.I0Itec.zkclient.ZkClient=DEBUG
And add dependency
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
Then you can see logs in console.

Trace for multiple Camel Context

I have two projects let's say - Project_1 and Project_2, and corresponding camel contexts, Configured as follows
<camel:camelContext id="project_1.context" trace="true">
<camel:contextScan />
</camel:camelContext>
<camel:camelContext id="project_2.context" trace="true">
<camel:contextScan />
</camel:camelContext>
with corresponding deployment units as project_1.jar, and project_2.jar, have been deployed in jboss.
But still I am not able to see traces for any of the CamelContext while starting my jboss.
log configuration for both projects are:
log4j.rootLogger=ERROR, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%c] %m%n
log4j.logger.org.apache.camel=ALL
both projects have added the dependency for slf4j
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
both projects have added the module dependency for slf4j in jboss-deployment-structure:
<module name ="org.slf4j"/>
Kindly help me to let me know the thing that I am missing.
Looks like your root logger is set as "Error".
In your project, if you have the messages logged in DEBUG or INFO mode, please try to change the root log level to "DEBUG" or "INFO" and verify

Failed to found StaticLoggerBinder in project

I have project with some modules. In parent I have defined:
org.apache.logging.log4j
log4j-slf4j-impl
${version.log4j}
runtime
but when I want to deploy application then StaticLoggerBinder is not found:
No org.slf4j.impl.StaticLoggerBinder found in ClassPath, trying with log4j...
but when I add depenedcy just into this project
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${version.log4j}</version>
</dependency>
then 2 StaticLoggerBinder is founded:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/hudect/.m2/repository/org/slf4j/slf4j-log4j12/1.7.5/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/hudect/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.0-rc1/log4j-slf4j-impl-2.0-rc1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
as you can see second one is from my parent project. I am really confused why this happens. Can someone me explain me how should I fix it ?
Do you also have the log4j-core and log4j-api dependencies?

Categories