gpt4 book ai didi

java - 无法在类 org.apache.logging.log4j.core.layout.JsonLayout 中为元素 JsonLayout 调用工厂方法

转载 作者:搜寻专家 更新时间:2023-10-31 20:32:47 27 4
gpt4 key购买 nike

我正在尝试通过 log4j2 以 JSON 格式登录。

这是我的 log4j2.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug" name="MyApp" packages="org.apache.logging.log4j.core.layout.JSONLayout">
<Appenders>
<RollingRandomAccessFile name="RollingRandomAccessFile" fileName="logs/app3.log"
filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz" append="false">
<JsonLayout/>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="250 MB"/>
</Policies>
<DefaultRolloverStrategy max="20"/>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="RollingRandomAccessFile"/>
</Root>
</Loggers>
</Configuration>

这些是我使用的依赖项:

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>net.logstash.log4j</groupId>
<artifactId>jsonevent-layout</artifactId>
<version>1.7</version>
</dependency><dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>

当我运行程序时,出现如下错误:

543 main ERROR Unable to invoke factory method in class class org.apache.logging.log4j.core.layout.JsonLayout for element JsonLayout.

调试:

2016-05-09 16:06:04,909 main DEBUG Initializing configuration XmlConfiguration[location=/home/mrunal/repo/jigsaw/jigsaw/jigsaw-solution/jigsaw-matchmanager-business/target/classes/log4j2.xml]
2016-05-09 16:06:04,916 main DEBUG Installed script engines
2016-05-09 16:06:05,717 main DEBUG Oracle Nashorn Version: 1.8.0_91, Language: ECMAScript, Threading: Not Thread Safe, Compile: true, Names: {nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript}
2016-05-09 16:06:05,823 main DEBUG Took 0.104995 seconds to load 14 plugins from package org.apache.logging.log4j.core.layout
2016-05-09 16:06:05,824 main DEBUG PluginManager 'Core' found 97 plugins
2016-05-09 16:06:05,824 main DEBUG PluginManager 'Level' found 0 plugins
2016-05-09 16:06:05,831 main DEBUG No scheduled items
2016-05-09 16:06:05,835 main DEBUG PluginManager 'Lookup' found 13 plugins
2016-05-09 16:06:05,837 main DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.JsonLayout].
2016-05-09 16:06:05,853 main DEBUG PluginManager 'TypeConverter' found 23 plugins
2016-05-09 16:06:05,863 main DEBUG createLayout(locationInfo="false", properties="false", complete="false", compact="false", eventEol="false", charset="UTF-8")
2016-05-09 16:06:05,864 main ERROR Unable to invoke factory method in class class org.apache.logging.log4j.core.layout.JsonLayout for element JSONLayout.
2016-05-09 16:06:05,865 main DEBUG Building Plugin[name=TimeBasedTriggeringPolicy, class=org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy].
2016-05-09 16:06:05,867 main DEBUG createPolicy(interval="null", modulate="null")
2016-05-09 16:06:05,868 main DEBUG Building Plugin[name=SizeBasedTriggeringPolicy, class=org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy].
2016-05-09 16:06:05,869 main DEBUG createPolicy(size="250 MB")
2016-05-09 16:06:05,872 main DEBUG Building Plugin[name=Policies, class=org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy].
2016-05-09 16:06:05,882 main DEBUG createPolicy(={TimeBasedTriggeringPolicy(nextRolloverMillis=0, interval=1, modulate=false), SizeBasedTriggeringPolicy(size=262144000)})
2016-05-09 16:06:05,882 main DEBUG Building Plugin[name=DefaultRolloverStrategy, class=org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy].
2016-05-09 16:06:05,887 main DEBUG createStrategy(max="20", min="null", fileIndex="null", compressionLevel="null", ={}, stopCustomActionsOnError="true", Configuration(/home/mrunal/repo/jigsaw/jigsaw/jigsaw-solution/jigsaw-matchmanager-business/target/classes/log4j2.xml))
2016-05-09 16:06:05,888 main DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender].
2016-05-09 16:06:05,892 main DEBUG createAppender(fileName="logs/app3.log", filePattern="logs/${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz", append="false", name="RollingRandomAccessFile", immediateFlush="null", bufferSize="null", Policies(CompositeTriggeringPolicy(policies=[TimeBasedTriggeringPolicy(nextRolloverMillis=0, interval=1, modulate=false), SizeBasedTriggeringPolicy(size=262144000)])), DefaultRolloverStrategy(DefaultRolloverStrategy(min=1, max=20)), JSONLayout(null), Filter=null, ignoreExceptions="null", advertise="null", advertiseURI="null", Configuration(/home/mrunal/repo/jigsaw/jigsaw/jigsaw-solution/jigsaw-matchmanager-business/target/classes/log4j2.xml))
2016-05-09 16:06:05,893 main INFO Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory.
2016-05-09 16:06:05,894 main DEBUG PluginManager 'Converter' found 38 plugins
2016-05-09 16:06:05,895 main DEBUG Starting OutputStreamManager SYSTEM_OUT.false-2
2016-05-09 16:06:05,909 main DEBUG Starting RollingRandomAccessFileManager logs/app3.log
2016-05-09 16:06:05,914 main DEBUG PluginManager 'FileConverter' found 2 plugins
2016-05-09 16:06:05,935 main DEBUG Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin].
2016-05-09 16:06:05,936 main DEBUG createAppenders(={RollingRandomAccessFile})
2016-05-09 16:06:05,936 main DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
2016-05-09 16:06:05,937 main DEBUG createAppenderRef(ref="RollingRandomAccessFile", level="null", Filter=null)
2016-05-09 16:06:05,937 main DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger].
2016-05-09 16:06:05,938 main DEBUG createLogger(additivity="null", level="TRACE", includeLocation="null", ={RollingRandomAccessFile}, ={}, Configuration(/home/mrunal/repo/jigsaw/jigsaw/jigsaw-solution/jigsaw-matchmanager-business/target/classes/log4j2.xml), Filter=null)
2016-05-09 16:06:05,941 main DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin].
2016-05-09 16:06:05,943 main DEBUG createLoggers(={root})
2016-05-09 16:06:05,944 main DEBUG Configuration XmlConfiguration[location=/home/mrunal/repo/jigsaw/jigsaw/jigsaw-solution/jigsaw-matchmanager-business/target/classes/log4j2.xml] initialized
2016-05-09 16:06:05,952 main DEBUG Starting configuration XmlConfiguration[location=/home/mrunal/repo/jigsaw/jigsaw/jigsaw-solution/jigsaw-matchmanager-business/target/classes/log4j2.xml]
2016-05-09 16:06:05,952 main DEBUG Started configuration XmlConfiguration[location=/home/mrunal/repo/jigsaw/jigsaw/jigsaw-solution/jigsaw-matchmanager-business/target/classes/log4j2.xml] OK.
2016-05-09 16:06:05,953 main DEBUG Shutting down OutputStreamManager SYSTEM_OUT.false-1
2016-05-09 16:06:05,953 main DEBUG Stopped org.apache.logging.log4j.core.config.DefaultConfiguration@7de26db8 OK
2016-05-09 16:06:06,027 main DEBUG Registering MBean org.apache.logging.log4j2:type=1a6c5a9e
2016-05-09 16:06:06,030 main DEBUG Registering MBean org.apache.logging.log4j2:type=1a6c5a9e,component=StatusLogger
2016-05-09 16:06:06,032 main DEBUG Registering MBean org.apache.logging.log4j2:type=1a6c5a9e,component=ContextSelector
2016-05-09 16:06:06,034 main DEBUG Registering MBean org.apache.logging.log4j2:type=1a6c5a9e,component=Loggers,name=
2016-05-09 16:06:06,036 main DEBUG Registering MBean org.apache.logging.log4j2:type=1a6c5a9e,component=Appenders,name=RollingRandomAccessFile
2016-05-09 16:06:06,041 main DEBUG Reconfiguration complete for context[name=1a6c5a9e] at URI /home/mrunal/repo/jigsaw/jigsaw/jigsaw-solution/jigsaw-matchmanager-business/target/classes/log4j2.xml (org.apache.logging.log4j.core.LoggerContext@732c2a62) with optional ClassLoader: null
2016-05-09 16:06:06,041 main DEBUG Shutdown hook enabled. Registering a new one.
16-05-09 16:06:06,043 main DEBUG LoggerContext[name=1a6c5a9e, org.apache.logging.log4j.core.LoggerContext@732c2a62] started OK.

是否有我遗漏的依赖项或其他问题?请提出我可以尝试解决此问题的可能方法。如果您知道以 Logstash Json 格式编写日志的更好解决方案,您可能会建议。

最佳答案

我怀疑您缺少 Jackson 依赖项之一。

你有 jackson-core-asl,我认为你需要这三个:

  1. com.fasterxml.jackson.core:jackson-core:jar:2.6.3
  2. com.fasterxml.jackson.core:jackson-databind:jar:2.6.3
  3. com.fasterxml.jackson.core:jackson-annotations:jar:2.6.0

依赖项的最终真实来源是 dependency tree Log4j 2 实现模块。

您可以通过设置 <Configuration status="debug" ... 获得有关该问题的更多详细信息在你的配置中。

关于java - 无法在类 org.apache.logging.log4j.core.layout.JsonLayout 中为元素 JsonLayout 调用工厂方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37043768/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com