2

I have created a sample java project which contains servlets and servlet code is having log entries to print the log messages. I am using SLF$j to print the logs in the servlets. This entire project is made as a "sampleProject.jar" files with no manifest.mf file. I am using this jar file in other project which runs on a tomcat(Web-application). If i run this web-application from tomcat which contains "sampleProject.jar". I am not able to see the log messages which i have written in the servet code(from jar) but the application is working as expected without printing the logs. By above setup i could not be able to see the logs printed, that's why i created the log4j.properties file with appenders as console and file and placed the binding libraries(log4j.jar, slf4j-logfj12.jar) along with the slf4j. Now i created the jar file again with the additional changes.Now also i could not be able to print the logs, i am getting the following error in the console.

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.

Please guide if i am doing wrong by looking at the above explanation.

Am i creating a sampleProject.jar incorrectly? Why i am getting the the above error even i placed the required bindings?

M.S.Naidu
  • 2,239
  • 5
  • 32
  • 56

1 Answers1

0

Do you have one of these files on your classpath slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar?

Please read the SLF4J documentation: http://www.slf4j.org/codes.html#StaticLoggerBinder

Failed to load class org.slf4j.impl.StaticLoggerBinder

This error is reported when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory. This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.

SINCE 1.6.0 As of SLF4J version 1.6, in the absence of a binding, SLF4J will default to a no-operation (NOP) logger implementation.

You can download SLF4J bindings from the project download page.

Community
  • 1
  • 1
Bruno
  • 304
  • 4
  • 10
  • Hello @Bruno, I am adding required bindings in the classpath of jar file, I have also mentioned that in above explanation. – M.S.Naidu Jun 03 '15 at 04:46
  • Hi @M.S.Naidu, sorry, I haven't read your entire post. Check your tomcat classpath. Copying all your dependencies into TOMCAT_HOME/lib could fix it. This blog post could also help you: http://adfinmunich.blogspot.de/2012/03/how-to-configure-tomcat-to-use-slf4j.html – Bruno Jun 03 '15 at 12:47
  • 1
    Some good answers that might help you: http://stackoverflow.com/questions/8012595/tomcat-logging-with-slf4j-and-log4j – Bruno Jun 03 '15 at 12:52