Logback and SLF4J software configuration

I am using Logback and SLF4J in a tomcat based web application. I do not use the logback.xml file. Everything is done programmatically. However, from time to time I received the following error message:

java.lang.ClassCastException: org.slf4j.helpers.SubstituteLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext.

and this is the part of the code that throws this exception:

LoggerContext logCtx = (LoggerContext) LoggerFactory
                .getILoggerFactory();

I would like to know that I am doing something wrong or not. Please, help.

+4
source share
1 answer

, SLF4J factory, . LoggerFactory , . , Logback, LoggerContext. - , , , LoggerContext. private static final Logger = LoggerFactory.getLogger("...") , LoggerContext, , .

+4

Source: https://habr.com/ru/post/1523545/


All Articles