I'm having issues during the starting of my Tomcat services due to Logback.
Context :
I did an upgrade of Logback, slf4j and jackson-core in order to use logback-logstash-encoder and print logs in json format when the app is deployed on cloud infrastructure.
So, now I'm using :
- Logback ==> 1.3.x series
- Slf4j ==> 2.0.x series
- Jackson ==> 2.15 series
- Java 8
- Spring 5
Since this upgrade, when I try to test if everything works well, I'm getting this error :
ERROR :
Failed to instantiate [ch.qos.logback.classic.LoggerContext] Reported exception: ch.qos.logback.core.LogbackException: Failed to initialize or to run Configurator: ch.qos.logback.classic.util.DefaultJoranConfigurator at ch.qos.logback.classic.util.ContextInitializer.invokeConfigure(ContextInitializer.java:133) at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:103) at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:66) at ch.qos.logback.classic.spi.LogbackServiceProvider.initializeLoggerContext(LogbackServiceProvider.java:52) at ch.qos.logback.classic.spi.LogbackServiceProvider.initialize(LogbackServiceProvider.java:41) at org.slf4j.LoggerFactory.bind(LoggerFactory.java:152) at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:139) at org.slf4j.LoggerFactory.getProvider(LoggerFactory.java:421) at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:407) at ch.qos.logback.classic.util.StatusViaSLF4JLoggerFactory.addStatus(StatusViaSLF4JLoggerFactory.java:34) at ch.qos.logback.classic.util.StatusViaSLF4JLoggerFactory.addInfo(StatusViaSLF4JLoggerFactory.java:22)
Deploying web application directory [tomcat/]
Caused by: java.lang.NullPointerException at java.util.ResourceBundle.containsKey(ResourceBundle.java:1821) at my.package.for.implementing.MyPropertyDefiner.getPropertyValue(MyPropertyDefiner.java:16)
at ch.qos.logback.core.model.processor.DefineModelHandler.postHandle(DefineModelHandler.java:120) at ch.qos.logback.core.model.processor.DefaultProcessor.mainTraverse(DefaultProcessor.java:216) at ch.qos.logback.core.model.processor.DefaultProcessor.mainTraverse(DefaultProcessor.java:211)
Part of Logback file that causes the issue :
<define name="LogDirectory" class="my.package.for.implementing.MyPropertyDefiner"> <myProperty>placeholder.property</myProperty> </define>
I also have a resource file (let's call it logback-myApp.properties) in which the different paths to store logs are declared and the levels of logs. So at the startup, when logback tries to initialize its Configurator, it should retrieve the properties of the developer (logs files path and levels logs) from the logback-myApp.properties file and give it to the MyPropertyDefiner.java class.
But it is not the case because it seems like the "placeholder.property" which is inside element is not taken into account. And that's why I'm getting NPE.
I tried also to add in logback.xml file:
<property resource="logback-myApp.properties"/>
but the value of placeholders are still ignored. And I think also I cannot use this element because it takes the default placeholders properties during startup. Not mine.
I cannot either use the element also because it's not a Spring boot app, but a Spring app.
Do you have an idea please ? How can I fix this issue ? Thanks.