log4j cassandra appender异常

btqmn9zl  于 2021-06-14  发布在  Cassandra
关注(0)|答案(1)|浏览(331)

我想用cassandra appender bu向cassandra db发送日志消息ı 下面提到了一个错误,
我已经在docker上创建了独立的cassandra,并在本地主机9042上使用demo keyspace和logs表

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager$AbstractFactoryData.<init>(I)V
    at org.apache.logging.log4j.nosql.appender.cassandra.CassandraManager$FactoryData.<init>(CassandraManager.java:193)
    at org.apache.logging.log4j.nosql.appender.cassandra.CassandraManager$FactoryData.<init>(CassandraManager.java:176)
    at org.apache.logging.log4j.nosql.appender.cassandra.CassandraManager.getManager(CassandraManager.java:127)
    at org.apache.logging.log4j.nosql.appender.cassandra.CassandraAppender$Builder.build(CassandraAppender.java:177)
    at org.apache.logging.log4j.nosql.appender.cassandra.CassandraAppender$Builder.build(CassandraAppender.java:52)
    at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:964)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:904)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:896)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:548)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:620)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:637)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
    at org.apache.logging.log4j.core.async.AsyncLoggerContext.start(AsyncLoggerContext.java:76)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
    at org.apache.commons.logging.LogAdapter$Log4jLog.<clinit>(LogAdapter.java:155)
    at org.apache.commons.logging.LogAdapter$Log4jAdapter.createLog(LogAdapter.java:122)

依赖关系文件包括

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
    <version>2.1.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>com.datastax.cassandra</groupId>
    <artifactId>cassandra-driver-core</artifactId>
    <version>3.6.0</version>
</dependency>
<dependency>
     <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-nosql</artifactId>
    <version>2.8.1</version>
</dependency>

附录conf如下所述,

<Cassandra  name="Cassandra" clusterName="MyCluster" keyspace="demo" table="log" bufferSize="10" batched="true">
            <SocketAddress host="localhost" port="9042" />
            <ColumnMapping name="id" pattern="%uuid{TIME}" type="java.util.UUID" />
            <ColumnMapping name="timeid" literal="now()" />
            <ColumnMapping name="message" pattern="%message" />
            <ColumnMapping name="level" pattern="%level" />
            <ColumnMapping name="marker" pattern="%marker" />
            <ColumnMapping name="logger" pattern="%logger" />
            <ColumnMapping name="timestamp" type="java.util.Date" />
            <ColumnMapping name="mdc" type="org.apache.logging.log4j.spi.ThreadContextMap" />
            <ColumnMapping name="ndc" type="org.apache.logging.log4j.spi.ThreadContextStack" />
        </Cassandra>                                            
</Appenders>

依赖树log4j2相关分支如下所述

+- org.springframework.boot:spring-boot-starter-log4j2:jar:2.1.5.RELEASE:compile
[INFO] |     |  +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.11.2:compile
[INFO] |     |  |  \- org.apache.logging.log4j:log4j-api:jar:2.11.2:compile
[INFO] |     |  +- org.apache.logging.log4j:log4j-core:jar:2.11.2:compile
[INFO] |     |  +- org.apache.logging.log4j:log4j-jul:jar:2.11.2:compile
[INFO] |     |  \- org.slf4j:jul-to-slf4j:jar:1.7.26:compile
 +- com.lmax:disruptor:jar:3.3.6:compile
[INFO] |     +- com.datastax.cassandra:cassandra-driver-core:jar:3.6.0:compile
[INFO] |     |  +- io.netty:netty-handler:jar:4.1.36.Final:compile
[INFO] |     |  |  +- io.netty:netty-common:jar:4.1.36.Final:compile
[INFO] |     |  |  +- io.netty:netty-buffer:jar:4.1.36.Final:compile
[INFO] |     |  |  +- io.netty:netty-transport:jar:4.1.36.Final:compile
[INFO] |     |  |  |  \- io.netty:netty-resolver:jar:4.1.36.Final:compile
[INFO] |     |  |  \- io.netty:netty-codec:jar:4.1.36.Final:compile
[INFO] |     |  +- com.google.guava:guava:jar:19.0:compile
[INFO] |     |  +- io.dropwizard.metrics:metrics-core:jar:4.0.5:compile
[INFO] |     |  +- com.github.jnr:jnr-ffi:jar:2.1.7:compile
[INFO] |     |  |  +- com.github.jnr:jffi:jar:1.2.16:compile
[INFO] |     |  |  +- com.github.jnr:jffi:jar:native:1.2.16:runtime
[INFO] |     |  |  +- org.ow2.asm:asm:jar:5.0.3:compile
[INFO] |     |  |  +- org.ow2.asm:asm-commons:jar:5.0.3:compile
[INFO] |     |  |  +- org.ow2.asm:asm-analysis:jar:5.0.3:compile
[INFO] |     |  |  +- org.ow2.asm:asm-tree:jar:5.0.3:compile
[INFO] |     |  |  +- org.ow2.asm:asm-util:jar:5.0.3:compile
[INFO] |     |  |  \- com.github.jnr:jnr-x86asm:jar:1.0.2:compile
[INFO] |     |  \- com.github.jnr:jnr-posix:jar:3.0.44:compile
[INFO] |     |     \- com.github.jnr:jnr-constants:jar:0.9.9:compile
[INFO] |     \- org.apache.logging.log4j:log4j-nosql:jar:2.8.1:compile

我已经用log4j cassandra更改了log4j nosql依赖关系,并且为cassandra驱动程序核心添加了排除项,用于度量核心下面提到的异常更改

<dependency>
    <groupId>com.datastax.cassandra</groupId>
    <artifactId>cassandra-driver-core</artifactId>
    <exclusions>
        <exclusion>
            <groupId>io.dropwizard.metrics</groupId>
            <artifactId>metrics-core</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-cassandra</artifactId>
</dependency>
Exception in thread "main" java.lang.NoClassDefFoundError: com/codahale/metrics/MetricRegistry
    at com.datastax.driver.core.Metrics.<init>(Metrics.java:45)
    at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1501)
    at com.datastax.driver.core.Cluster.init(Cluster.java:208)
    at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:376)
    at com.datastax.driver.core.Cluster.connect(Cluster.java:332)
    at org.apache.logging.log4j.cassandra.CassandraManager.startupInternal(CassandraManager.java:74)
    at org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.startup(AbstractDatabaseManager.java:222)
    at org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.start(AbstractDatabaseAppender.java:172)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:266)
    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:548)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:620)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:637)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
    at org.apache.logging.log4j.core.async.AsyncLoggerContext.start(AsyncLoggerContext.java:76)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
    at org.apache.commons.logging.LogAdapter$Log4jLog.<clinit>(LogAdapter.java:155)
    at org.apache.commons.logging.LogAdapter$Log4jAdapter.createLog(LogAdapter.java:122)
    at org.apache.commons.logging.LogAdapter.createLog(LogAdapter.java:89)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:67)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:59)
    at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:194)
    at Application.main(Application.java:27)
Caused by: java.lang.ClassNotFoundException: com.codahale.metrics.MetricRegistry
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 24 more

依赖关系树是

+- org.springframework.boot:spring-boot-starter-log4j2:jar:2.1.5.RELEASE:compile
[INFO] |     |  +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.11.2:compile
[INFO] |     |  |  \- org.apache.logging.log4j:log4j-api:jar:2.11.2:compile
[INFO] |     |  +- org.apache.logging.log4j:log4j-core:jar:2.11.2:compile
[INFO] |     |  +- org.apache.logging.log4j:log4j-jul:jar:2.11.2:compile
[INFO] |     |  \- org.slf4j:jul-to-slf4j:jar:1.7.26:compile
[INFO] |     +- org.springframework.boot:spring-boot-configuration-processor:jar:2.1.5.RELEASE:compile
[INFO] |     +- com.lmax:disruptor:jar:3.3.6:compile
[INFO] |     +- com.datastax.cassandra:cassandra-driver-core:jar:3.6.0:compile
[INFO] |     |  +- io.netty:netty-handler:jar:4.1.36.Final:compile
[INFO] |     |  |  +- io.netty:netty-common:jar:4.1.36.Final:compile
[INFO] |     |  |  +- io.netty:netty-buffer:jar:4.1.36.Final:compile
[INFO] |     |  |  +- io.netty:netty-transport:jar:4.1.36.Final:compile
[INFO] |     |  |  |  \- io.netty:netty-resolver:jar:4.1.36.Final:compile
[INFO] |     |  |  \- io.netty:netty-codec:jar:4.1.36.Final:compile
[INFO] |     |  +- com.google.guava:guava:jar:19.0:compile
[INFO] |     |  +- com.github.jnr:jnr-ffi:jar:2.1.7:compile
[INFO] |     |  |  +- com.github.jnr:jffi:jar:1.2.16:compile
[INFO] |     |  |  +- com.github.jnr:jffi:jar:native:1.2.16:runtime
[INFO] |     |  |  +- org.ow2.asm:asm:jar:5.0.3:compile
[INFO] |     |  |  +- org.ow2.asm:asm-commons:jar:5.0.3:compile
[INFO] |     |  |  +- org.ow2.asm:asm-analysis:jar:5.0.3:compile
[INFO] |     |  |  +- org.ow2.asm:asm-tree:jar:5.0.3:compile
[INFO] |     |  |  +- org.ow2.asm:asm-util:jar:5.0.3:compile
[INFO] |     |  |  \- com.github.jnr:jnr-x86asm:jar:1.0.2:compile
[INFO] |     |  \- com.github.jnr:jnr-posix:jar:3.0.44:compile
[INFO] |     |     \- com.github.jnr:jnr-constants:jar:0.9.9:compile
[INFO] |     \- org.apache.logging.log4j:log4j-cassandra:jar:2.11.2:compile

我已经添加了该站点的度量标准jmx依赖性指南
度量4兼容性,但应用程序在生成记录器时再次抛出下面的异常

<dependency>
  <groupId>io.dropwizard.metrics</groupId>
  <artifactId>metrics-jmx</artifactId>
  <version>4.0.5</version>
</dependency>
Exception in thread "main" java.lang.NoClassDefFoundError: com/codahale/metrics/JmxReporter
    at com.datastax.driver.core.Metrics.<init>(Metrics.java:146)
    at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1501)
    at com.datastax.driver.core.Cluster.init(Cluster.java:208)
    at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:376)
    at com.datastax.driver.core.Cluster.connect(Cluster.java:332)
    at org.apache.logging.log4j.cassandra.CassandraManager.startupInternal(CassandraManager.java:74)
    at org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.startup(AbstractDatabaseManager.java:222)
    at org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.start(AbstractDatabaseAppender.java:172)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:266)
    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:548)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:620)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:637)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
    at org.apache.logging.log4j.core.async.AsyncLoggerContext.start(AsyncLoggerContext.java:76)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
    at com.example.demo.Application.<clinit>(Application.java:13)
Caused by: java.lang.ClassNotFoundException: com.codahale.metrics.JmxReporter
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

谢谢您

piok6c0g

piok6c0g1#

正如我所看到的,您正在使用log4j 2.8.1和nosql记录器,但是spring使用的是2.11.2。
您应该从spring-boot-starter-log4j2中排除log4j2。

相关问题