Closed TulleyT closed 5 years ago
研究了一下异常抛出的位置,抛出该异常是因为在SLF4JLOG4J_CLASSNAME.equals(delegate.getClass().getName())这个判断为false 其中SLF4JLOG4J_CLASSNAME这个常量的值为"org.apache.logging.slf4j.Log4jLogger" 但是实际上使用slf4j+log4j的组合最后delegate.getClass().getName()为“org.slf4j.impl.Log4jLoggerAdapter” 而"org.apache.logging.slf4j.Log4jLogger"是slf4j+log4j2的桥接包中的路径,所以当项目日志框架为slf4j+log4j的时候会抛出异常
而在com.alibaba.nacos.client.logger.LoggerFactory中的注释中说支持slf4j + slf4j-log4j12 + log4j,那很明显是不是在com.alibaba.nacos.client.logger.slf4j.Slf4jLogger的构造方法中的判断逻辑少了对于这个组合的判断?而且我在0.6.0版本的nacos-client中的com.alibaba.nacos.client.logger.option包中都没有发现对log4j的ActiveOption的实现
我也遇到了这个问题,log4j里面配置了好多东西,不想升级,还不知道怎么办
org.slf4j.impl.Log4jLoggerAdapter
原zookeeper 改nacos 报这个异常,大家解决了吗?org.apache.catalina.loader.StandardClassLoader@11bbdc80
JM.Log:ERROR Failed to get Slf4jLogger
java.lang.IllegalArgumentException: delegate must be logback impl or slf4j-log4j impl
at com.alibaba.nacos.client.logger.slf4j.Slf4jLogger.
同样的问题,大家解决了吗?
Log4J1 兼容升级到 Log4J2可以用log4j-1.2-api
的Bridge
他这边的Log4J日志实现是会往日志的配置里另外再塞Appender的, 所以只兼容Log4J2
如果不在意它的NAMING_LOGGER
的话 直接无视就可以了
升级到dubbo 2.7.1 可以解决
升级到dubbo 2.7.1 可以解决
经过测试是可以的具体POM详见
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Dubbo -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Dubbo Registry Nacos -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-nacos</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</dependency>
provider启动方式为 com.alibaba.dubbo.container.Main.main(new String[] { "spring" }) main函数 spring配置文件指明了日志输出方式为slf4j
maven依赖中添加了如下依赖
provider启动时nacos报错: Tue Dec 18 13:32:19 CST 2018 sun.misc.Launcher$AppClassLoader@2a139a55 JM.Log:ERROR Failed to get Slf4jLogger java.lang.IllegalArgumentException: delegate must be logback impl or slf4j-log4j impl at com.alibaba.nacos.client.logger.slf4j.Slf4jLogger.(Slf4jLogger.java:69)
at com.alibaba.nacos.client.logger.slf4j.Slf4jLoggerFactory.getLogger(Slf4jLoggerFactory.java:36)
at com.alibaba.nacos.client.logger.LoggerFactory.getLogger(LoggerFactory.java:77)
at com.alibaba.nacos.client.naming.utils.LogUtils.(LogUtils.java:44)
at com.alibaba.nacos.client.naming.NacosNamingService.init(NacosNamingService.java:89)
at com.alibaba.nacos.client.naming.NacosNamingService.(NacosNamingService.java:109)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.alibaba.nacos.api.naming.NamingFactory.createNamingService(NamingFactory.java:43)
at com.alibaba.nacos.api.NacosFactory.createNamingService(NacosFactory.java:74)
at com.alibaba.dubbo.registry.nacos.NacosRegistryFactory.buildNamingService(NacosRegistryFactory.java:58)
at com.alibaba.dubbo.registry.nacos.NacosRegistryFactory.createRegistry(NacosRegistryFactory.java:51)
at com.alibaba.dubbo.registry.support.AbstractRegistryFactory.getRegistry(AbstractRegistryFactory.java:96)
at com.alibaba.dubbo.registry.RegistryFactory$Adaptive.getRegistry(RegistryFactory$Adaptive.java)
at com.alibaba.dubbo.registry.integration.RegistryProtocol.getRegistry(RegistryProtocol.java:203)
at com.alibaba.dubbo.registry.integration.RegistryProtocol.export(RegistryProtocol.java:137)
at com.alibaba.dubbo.qos.protocol.QosProtocolWrapper.export(QosProtocolWrapper.java:60)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:98)
at com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:55)
at com.alibaba.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java)
at com.alibaba.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:513)
at com.alibaba.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:358)
at com.alibaba.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:317)
at com.alibaba.dubbo.config.ServiceConfig.export(ServiceConfig.java:216)
at com.alibaba.dubbo.config.spring.ServiceBean.export(ServiceBean.java:291)
at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:131)
at com.alibaba.dubbo.config.spring.ServiceBean.onApplicationEvent(ServiceBean.java:53)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:337)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:882)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545)
at com.alibaba.dubbo.container.spring.SpringContainer.start(SpringContainer.java:50)
at com.alibaba.dubbo.container.Main.main(Main.java:86)
at com.sinosoft.ehosp.test.BootMain.main(BootMain.java:6)