gpt4 book ai didi

java - 将log4j 1.2.14升级到2.12.1错误没有配置根记录器并且未创建日志文件

转载 作者:行者123 更新时间:2023-12-04 11:37:40 26 4
gpt4 key购买 nike

我们正在将log4j 1.2.14升级到2.12.1,我有log4j2.properties文件,如下所示

status = error

log4j2.appender.console.type = Console
log4j2.appender.console.name = LogToConsole
log4j2.appender.console.layout.type = PatternLayout
log4j2.appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n

#log4j2.appender.file.type = File
#log4j2.appender.file.name = LogToFile
#log4j2.appender.file.fileName=logs/app.log
#log4j2.appender.file.layout.type=PatternLayout
#log4j2.appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n

# Rotate log file
log4j2.appender.rolling.type = RollingRandomAccessFile
log4j2.appender.rolling.name = LogToRollingRandomAccessFile
log4j2.appender.rolling.fileName = ${server.home}/logs/server.log
log4j2.appender.rolling.filePattern = logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz
log4j2.appender.rolling.layout.type = PatternLayout
log4j2.appender.rolling.layout.pattern = %d %p %C{1.} [%t] %m%n
log4j2.appender.rolling.policies.type = Policies
log4j2.appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
log4j2.appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.rolling.policies.size.size=10MB
log4j2.appender.rolling.strategy.type = DefaultRolloverStrategy
log4j2.appender.rolling.strategy.max = 10

# Log to console and rolling file
#logger.app.type = AsyncLogger
log4j2.logger.app.name = com.ssl.server
log4j2.logger.app.level = info
log4j2.logger.app.additivity = false
log4j2.logger.app.appenderRef.rolling.ref = LogToRollingRandomAccessFile
log4j2.logger.app.appenderRef.console.ref = LogToConsole

log4j2.rootLogger.level = info
log4j2.rootLogger.appenderRef.stdout.ref = LogToConsole

我的pom.xml中具有以下依赖性
    <dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.12.1</version>
</dependency>

我正在如下初始化记录器
private static final org.apache.logging.log4j.Logger LOG = org.apache.logging.log4j.LogManager.getLogger(SSLServer.class.getName());

当我使用 main()启动独立的Java应用程序时出现以下错误并且未创建 server.log文件时,我对以下错误进行了一些研究,并且大多数文章都引用了 log4j2.xml配置,而 log4j2.properties中没有任何配置更改
log warn: org.apache.logging.log4j.status.StatusLogger - No Root logger was configured, creating default ERROR-level Root logger with Console appender
No Root logger was configured, creating default ERROR-level Root logger with Console appender

最佳答案

几件事要看:

  • 确保您的类路径中没有任何其他log4j2配置文件。列表不小,可能会跳闸。看到它in the documentation here
  • 通过增加状态消息来从 log4j2 中获取调试信息:status = info(debugtrace)
  • 从所有属性中删除log4j2.作为前缀,以便log4j2.appender.console.type = Console成为appender.console.type = Console
  • 将文件记录添加到rootlogger中:rootLogger.appenderRef.rolling.ref = LogToFile
  • 关于java - 将log4j 1.2.14升级到2.12.1错误没有配置根记录器并且未创建日志文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58331217/

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