将log4j.properties转换为log4j2.properties

ckocjqey  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(131)

我正在从log4j 1.2迁移到log4j 2.22.0。问题是我的项目包含一个log4j.properties文件,我在将其转换为log4j2.properties时遇到了麻烦。我已经在这里进行了大量的讨论,到目前为止它没有任何帮助。任何人都有一个想法?这里是我的.properties文件。谢谢

!log4j.debug=true: Default is false. Outputs verbose info as log4j is configuring itself. 
log4j.debug=${log4j.isdebug}

log4j.rootCategory=${log4j.default.level},${log4j.appender}
log4j.category.fr.bowling=${log4j.mybowl.level}

log4j.category.org.apache.catalina=FATAL

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${log4j.path}/mybowl_main.log

log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=3
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%-5p %d [%t] %X{UserSessionId} %c{1} %30m%n

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

字符串
这是包含该部分的项目的development.properties

# logger Configuration of file: log4j.properties
log4j.default.level=ERROR
log4j.appender=CONSOLE,R
log4j.isdebug=false
log4j2.mybowl.level=DEBUG
log4j2.path=C:/LOGS/mybowl/


到现在还没有结果!

yruzcnhs

yruzcnhs1#

要从版本1.x配置转换到版本2.x配置,您可以使用org.apache.log4j.config.Log4j1ConfigurationConverter from log4j-1.2-api

# Download `log4j-1.2-api` with deps
mvn dependency:copy -DoutputDirectory=log4j -Dartifact=org.apache.logging.log4j:log4j-1.2-api:2.22.0
mvn dependency:copy -DoutputDirectory=log4j -Dartifact=org.apache.logging.log4j:log4j-core:2.22.0
mvn dependency:copy -DoutputDirectory=log4j -Dartifact=org.apache.logging.log4j:log4j-api:2.22.0
java -cp 'log4j/*' org.apache.log4j.config.Log4j1ConfigurationConverter -i=log4j.properties -o=log4j2.xml

字符串
您将获得此配置:

<?xml version="1.0"?>
<Configuration name="Log4j1">
  <Appenders>
    <RollingFile name="R" fileName="/mybowl_main.log" filePattern="/mybowl_main.log.%i">
      <PatternLayout pattern="%-5p %d [%t] %X{UserSessionId} %c{1} %30m%n"/>
      <Policies>
        <SizeBasedTriggeringPolicy size="10MB"/>
      </Policies>
      <DefaultRolloverStrategy max="3" fileIndex="min"/>
    </RollingFile>
    <Console name="CONSOLE" target="SYSTEM_OUT">
      <PatternLayout pattern="%-4r [%t] %-5p %c %ndc - %m%n"/>
    </Console>
  </Appenders>
  <Loggers>
    <Root level="${sys:log4j.default.level}">
      <AppenderRef ref="${sys:log4j.appender}"/>
    </Root>
    <Logger name="fr.bowling" level="${sys:log4j.mybowl.level}"/>
    <Logger name="org.apache.catalina" level="FATAL"/>
  </Loggers>
</Configuration>

备注:如果您愿意,可以将其转换为属性配置,但我不建议这样做,因为它是无用的复杂。

相关问题