When using Infinispan (or any other jBoss library for that matter)  and Logback in the same project you may end up getting this warning when running the project:

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console

Maybe you log to a persistent storage and you may miss important error messages, because they are logged to the console.

Solution 1: Start the application with specific parameter

One solution is to add the following parameter when starting the application:

-Dorg.jboss.logging.provider=slf4j

The relevant code is in org.jboss.logging.LoggerProviders which looks for the “org.jboss.logging.provider” environment variable.

 

Solution 2: Exclude log4j libraries from classpath

Another solution is to exclude all logging related classes from the classpath, as in org.jboss.logging.LoggerProviders it looking for various logging related classes and it looks for the logabck related classes at the very end!

When using gradle it is enough to add the following into build.gradle

configurations {
all*.exclude group: ‘org.apache.logging.log4j’
all*.exclude group: ‘org.apache.log4j’
all*.exclude group: ‘org.jboss.logmanager’
}

I am using Logback to do most of my logging. I am using a third party library for some computation. Luckily the library uses slf4j, meaning it’s agnostic of the logging implementation.

The library caches two collections of items and depending on the circumstances the item I am looking for may be in any of the two collections. This is not important. What is important, is that the library for some reason logs an error if an item cannot be found in the first collection.

I wanted to get rid of this message because it was cluttering my logs. But I didn’t want to disable all logging from this specific class, because it may print some useful logs. I just wanted to get rid of this specific log. There is a way to do it Continue reading