有人能帮我吗?
我正在从log4j 1转到2,但无法获得工作属性文件。滚动文件vds.log未出现
这是我以前的工作道具
# default properties to initialise log4j
log4j.rootLogger=INFO, rollingFile
# settings for specific packages
log4j.logger.com.wordnik.swagger=INFO
log4j.logger.org.apache.camel.component.servlet=INFO
log4j.logger.org.apache.camel.component.swagger=INFO
log4j.logger.org.apache.camel=INFO
# Console appender
# Uncomment when running locally
# log4j.appender.console=org.apache.log4j.ConsoleAppender
# log4j.appender.console.layout=org.apache.log4j.PatternLayout
# log4j.appender.console.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
log4j.appender.rollingFile.maxFileSize=10MB
log4j.appender.rollingFile.maxBackupIndex=10
log4j.appender.rollingFile.File=C:/logs/vds.log
log4j.appender.rollingFile.layout=org.apache.log4j.PatternLayout
log4j.appender.rollingFile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n
log4j.appender.rollingFile.append=true
这就是我尝试过的,但不起作用
status = debug
name= vds
# Log files location
property.basePath = c:/logs
appender.logger.com.wordnik.swagger=INFO
appender.logger.org.apache.camel.component.servlet=INFO
appender.logger.org.apache.camel.component.swagger=INFO
appender.logger.org.apache.camel=INFO
# RollingFileAppender name, pattern, path and rollover policy
appender.rolling.type = RollingFile
appender.rolling.name = fileLogger
appender.rolling.fileName= ${basePath}/app.log
appender.rolling.filePattern= ${basePath}/app_%d{yyyyMMdd}.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %level [%t] [%l] - %msg%n
appender.rolling.policies.type = Policies
# RollingFileAppender rotation policy
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.delete.type = Delete
appender.rolling.strategy.delete.basePath = ${basePath}
appender.rolling.strategy.delete.maxDepth = 10
appender.rolling.strategy.delete.ifLastModified.type = IfLastModified
# Delete all files older than 30 days
appender.rolling.strategy.delete.ifLastModified.age = 30d
# Configure root logger
rootLogger.level = debug
rootLogger.appenderRef.rolling.ref = fileLogger
聚甲醛
<!-- logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.16.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.16.0</version>
</dependency>
我看了其他的答案,但没有一个能帮到我。这就是为什么我求助于寻求帮助。有人能帮助我吗?提前感谢。
1条答案
按热度按时间eqoofvh91#
属性文件格式不是Log4j 2.x中的默认配置格式(它只在2.4中引入)。如果您要使用XML,
log4j-1.2-api
中有一个自动配置转换器,它可以使用以下命令将您的属性文件转换为XML:(我假设所有三个jar,
log4j-1.2-api
,log4j-api
和log4j-core
都在当前目录中)。(the缩进是我的)。备注:
max="1"
可能是转换器中的错误。如果您坚持使用属性格式,则记录器配置应如下所示: