java.lang.ClassCastException: org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext...Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext...but Logback is on the classpath....WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory 线程“main”java.lang.illegalargumentException中出现异常:loggerFactory...不是logback loggerContext,但logback在类路径上。
LoggerFactory is not a Logback LoggerContext but Logback is on the classpath..../logback-classic/1.1.11/logback-classic-1.1.11.jar!...日志: Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback...is on the classpath....已经在classpath中存在,这时候就应该意识到有Logback依赖冲突,在多个地方都有Logback的依赖。
().getLoggerFactory(); // 判断加载的日志工厂类是否为logback的LoggerContext,如果不是则抛出异常 Assert.isInstanceOf(LoggerContext.class..., factory, () -> String.format( "LoggerFactory is not a Logback LoggerContext...but Logback is on " + "the classpath....is not a Logback LoggerContext but Logback is on the classpath....is not a Logback LoggerContext but Logback is on the classpath.
相关异常信息如下: Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback...LoggerContext but Logback is on the classpath....其中关键新增在这里: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath....Either remove Logback or the competing implementation…… 就是说Logback已经在classpath中存在,但LoggerFactory并不是Logback...:logback-classic:jar:1.1.5:compile [INFO] | | | \- ch.qos.logback:logback-core:jar:1.1.5:compile [
版本 2.2.x 创建logback javaconfig myapp.BasicConfigurator public class BasicConfigurator extends ch.qos.logback.core.spi.ContextAwareBase...implements ch.qos.logback.classic.spi.Configurator { public BasicConfigurator() { }..., factory, String.format( "LoggerFactory is not a Logback LoggerContext...but Logback is on " + "the classpath....loggerContext) { loggerContext.stop(); loggerContext.reset(); if (isBridgeHandlerInstalled
测试代码 public class LogTest { private static Logger LOGGER = LoggerFactory.getLogger...问题2:我们加上logback的配置文件,仅仅在src/main/resources(相当于classpath)下加logback.xml,发现生成了日志文件(若没有设置日志文件路径,那么日志文件生成在当前工程下...源码解析 从LogTest.java开始 public class LogTest { private static Logger LOGGER = LoggerFactory.getLogger...slf4j会在classpath中寻找org/slf4j/impl/StaticLoggerBinder.class(会在具体的日志框架如log4j、logback等中存在),找到并完成绑定;同时,logback...也会在classpath中寻找配置文件,先找logback.configurationFile、没有则找logback.groovy,若logback.groovy也没有,则找logback-test.xml
static Logger LOGGER = LoggerFactory.getLogger(LogbackTest.class); public static void main(String...会去 classpath 下的 META-INF/services 目录下寻找 org.slf4j.spi.SLF4JServiceProvider 文件 然后读取其中的内容,并实例化 这里拿到的是 Provider...,并非 Logger initialize 大家注意看下 defaultLoggerContext 的类型 LoggerContext public class LoggerContext extends...) LogbackServiceProvider 的 initialize 方法会实例化 defaultLoggerContext(ch.qos.logback.classic.LoggerContext...我们会发现 DefaultJoranConfigurator invoke 上了,其 performMultiStepConfigurationFileSearch 方法寻找配置文件 优先级从高到低,会从 classpath
package chapters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; // 省略......ch.qos.logback.classic.LoggerContext#LoggerContext public LoggerContext() { super(); this.loggerCache...} catch (Exception t) { // see LOGBACK-1159 Util.report("Failed to instantiate [" + LoggerContext.class.getName..., updateStatus); } 先从启动参数中查找logback.configurationFile参数值,如果没有再从classpath中一次查找logback-test.xml -> logback.groovy...第13步:ch.qos.logback.classic.LoggerContext#getLogger(java.lang.String) @Override public Logger getLogger
具体源码如下(slf4j-api-1.7.7): private final static void bind() { try { // 查找classpath下所有的StaticLoggerBinder...staticLoggerBinderPathSet); fixSubstitutedLoggers(); ... } findPossibleStaticLoggerBinderPathSet方法用来查找当前classpath...(type)) { logFrameworkType = LogFrameworkType.LOGBACK; ch.qos.logback.classic.LoggerContext loggerContext...= (ch.qos.logback.classic.LoggerContext) LoggerFactory.getILoggerFactory(); for (ch.qos.logback.classic.Logger...rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); loggerMap.put
classpath:logback.xml 5 6 7...org.springframework.util.ResourceUtils; 9 import org.springframework.util.SystemPropertyUtils; 10 11 import ch.qos.logback.classic.LoggerContext...:" */ 18 public static final String CLASSPATH_URL_PREFIX = "classpath:"; 19 20 /** Extension...= ".xml"; 22 23 private static LoggerContext lc = (LoggerContext) LoggerFactory 24...app启动时会报错: java.lang.ClassCastException: org.slf4j.impl.Slf4jLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext
maxHistory */ private void doInitializer(String file, String level, int maxHistory) { LoggerContext...loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); Logger rootLogger = loggerContext.getLogger...ILoggingEvent> fileAppender = new RollingFileAppender(); fileAppender.setContext(loggerContext...encoder PatternLayoutEncoder encoder = new PatternLayoutEncoder(); encoder.setContext(loggerContext...{ private static final Logger logger = LoggerFactory.getLogger(LogbackContainerTest.class);
:$JAVA_HOME/bin:$PATH export CLASSPATH=....连接单机版的pulsar的测试代码:SimpleProducerAndCosnumer.java package com.tencent.tdmq.demo.cloud; import ch.qos.logback.classic.LoggerContext...= null) { LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator...创建订阅者 image.png 订阅者:sub-sfhuang image.png 6、修改本地代码: package com.tencent.tdmq.demo.cloud; import ch.qos.logback.classic.LoggerContext...= null) { LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator
(); loggerContext.getTurboFilterList().add(FILTER); } 主要初始化 LoggerContext,跟进 getLoggerContext() private...(); Assert.isInstanceOf(LoggerContext.class, factory, () -> String.format( "LoggerFactory is...not a Logback LoggerContext but Logback is on " + "the classpath....我们重新回到 AbstractLoggingSystem#initializeWithConventions ,如果 classpath 下 logback-test.groovy, logback-test.xml...logback-spring.groovy, logback-spring.xml 同样从 classpath 下逐个寻找,一旦找到直接返回;这也是为什么我们的日志配置文件是 logback-spring.xml
可以通过 StatusPrinter 来打印 Logback 的内部信息: LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory...12:59:22,261 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml...] 12:59:22,262 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy...] 12:59:22,262 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.xml...也就是说,Logback 会在 classpath 路径下先寻找 logback-test.xml 文件,没有找到的话,寻找 logback.groovy 文件,还没有的话,寻找 logback.xml
到底有没有关系,有何关系,我们慢慢往下看;先声明下 后面的分析都是基于 Spring Boot 默认的 Logback,其他日志组件可能有所不同,大家别带入错了 LoggerFactory 不管是我们用的...slf4j 方式 private static final Logger LOGGER = LoggerFactory.getLogger(TestWeb.class); 还是 Spring Boot...} autoConfig() 就不细跟了(感兴趣的可以去看:从源码来理解slf4j的绑定,以及logback对配置文件的加载),执行完之后,我们看下 LoggerContext 的 objectMap...的 objectMap 被置空了 说白了就是 Spring Boot 把 Logback 加载的日志配置给清空了,接下来就是 Spring Boot 加载日志配置信息到 LoggerContext 中...Boot 启动过程中会重置 LoggerContext,然后重新加载日志配置文件内容到 LoggerContext Spring Boot 2.7.18 先按优先级 logback-test.groovy
RequestParam(value = "packageName", defaultValue = "-1") String packageName) throws Exception { ch.qos.logback.classic.LoggerContext...loggerContext = (ch.qos.logback.classic.LoggerContext) LoggerFactory.getILoggerFactory(); Logger...logger = loggerContext.getLogger("root") } else { logger = loggerContext.getLogger(packageName...return; } logbackLevels.forEach(LoggerLevel::checkAndConvert); ch.qos.logback.classic.LoggerContext...loggerContext = (ch.qos.logback.classic.LoggerContext) LoggerFactory.getILoggerFactory(); for
业务中经常用到slf4j来写日志,但是没有深入研究过为啥通过这个就可以调用log4j或者logback的函数来写日志呢?...import org.slf4j.Logger; import org.slf4j.LoggerFactory; private static final Logger logger = LoggerFactory.getLogger...这里调用log4j或者Logback的实现。我的演示代码用的是logback。...LoggerFactory.getLogger(xxx.class) 追踪LoggerFactory.getLogger源码 public static Logger getLogger(Class...LoggerContext getLoggerContext(); LoggerContext getLoggerContext(String name); LoggerContext
:$JAVA_HOME/bin:$PATH export CLASSPATH=....连接单机版的pulsar的测试代码:SimpleProducerAndCosnumer.java package com.tencent.tdmq.demo.cloud; import ch.qos.logback.classic.LoggerContext...= null) { LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator...image.png 订阅者:sub-sfhuang image.png 6、修改本地代码: package com.tencent.tdmq.demo.cloud; import ch.qos.logback.classic.LoggerContext...= null) { LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator
提示的错误信息为: Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext...but Logback is on the classpath....Either remove Logback or the competing implementation (class org.apache.logging.slf4j.Log4jLoggerFactory
maxHistory */ private void doInitializer(String file, String level, int maxHistory) { LoggerContext...loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); Logger rootLogger = loggerContext.getLogger...ILoggingEvent> fileAppender = new RollingFileAppender(); fileAppender.setContext(loggerContext...encoder PatternLayoutEncoder encoder = new PatternLayoutEncoder(); encoder.setContext(loggerContext...{ private static final Logger logger = LoggerFactory.getLogger(LogbackContainerTest.class);
领取专属 10元无门槛券
手把手带您无忧上云