Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

slf4j logback substituteLogger

Tags:

slf4j

logback

I'm not able anymore to start my loggers using the gradle task `jettyRuǹ . The 1st issue with multiple bindings wasn't a problem. But now (after the upgrade to gradle 1.4, I guess) my loggers don't start. The slf4j doc says to reset the context programmatically, but I would prefer to do it by configuration as jettyRun is only used for development.

$ gradle jettyRun
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jettyRun
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/gradle-1.4/lib/logback-classic-1.0.9.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/bertrand/.gradle/caches/artifacts-23/filestore/ch.qos.logback/logback-classic/1.0.9/jar/258c3d8f956e7c8723f13fdea6b81e3d74201f68/logback-classic-1.0.9.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 [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
SLF4J: The following loggers will not work because they were created
SLF4J: during the default configuration phase of the underlying logging system.
SLF4J: See also http://www.slf4j.org/codes.html#substituteLogger
SLF4J: org.yajug.users.api.MembershipController
SLF4J: org.yajug.users.json.Serializer
SLF4J: org.yajug.users.api.MemberController
SLF4J: org.yajug.users.service.MemberServiceImpl
SLF4J: org.yajug.users.persistence.MongoConnector
like image 271
krampstudio Avatar asked Apr 14 '13 15:04

krampstudio


People also ask

Can I use SLF4J with Logback?

The configuration is Logback-specific but works seamlessly with SLF4J. With the proper dependencies and configuration in place, the same code from previous sections can be used to handle the logging. 4. The Log4j Setup

What is Simple Logging Facade for Java (SLF4J)?

Overview Simple Logging Facade for Java (abbreviated SLF4J) – acts as a facade for different logging frameworks (e.g. java.util.logging, logback, Log4j ). It offers a generic API making the logging independent of the actual implementation. This allows for different logging frameworks to coexist. It also helps migrate from one framework to another.

What is SLF4J’s JCL?

In the previous sections, we showed how the same code base can be used to support logging using different implementations. While this is the main promise and strength of SLF4J, it is also the goal behind JCL (Jakarta Commons Logging or Apache Commons Logging).

How to concatenate strings in SLF4J with Log4j?

SLF4J will concatenate Strings only when the debug level is enabled. To do the same with Log4J you need to add extra if block which will check if debug level is enabled or not: SLF4J standardized the logging levels which are different for the particular implementations.


1 Answers

Finally I found what was wrong:

  • The logging context is initialized lazily, at the first call to a logger.
  • In the context of my web app (a single page web app that do only async calls), the first page was calling 2 async requests
  • each request had a logger and the initialization was made concurrently, it's the reason why some of my loggers implementation where substituted by a nop impl.
  • by adding a logger call on the app startup, the context is initialized correctly
like image 137
krampstudio Avatar answered Oct 17 '22 00:10

krampstudio