我必须将文件:log4j配置从版本1转换为2。 但它必须是一对一的。 此操作后的日志必须与log4j版本1完全相同。
你能帮我把它从log4j 1转换成log4j2 ....
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<appender name="mylog" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="mylog.log"/>
<param name="RollingPolicy" value="org.apache.log4j.rolling.TimeBasedRollingPolicy"/>
<param name="ActiveFileName" value="mylog.log"/>
<param name="FileNamePattern" value="mylog-%d{yyyyMMdd-HHmm}.rolled"/>
<param name="TriggeringPolicy" value="org.apache.log4j.rolling.SizeBasedTriggeringPolicy"/>
<param name="maxFileSize" value="100000"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} [%t] %p - %m%n"/>
</layout>
</appender>
<logger name="mylogger" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="mylog"/>
</logger>
<root>
<level value="DEBUG"/>
<appender-ref ref="sysoutlog"/>
</root>
</Configuration>
答案 0 :(得分:1)
我相信这就是你要找的东西:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml> <!-- I use this just to get rid of eclipse XML schema warning -->
<Configuration status="warn" name="My configuration"> <!-- Modify status to get more verbose info -->
<Appenders>
<RollingFile name="mylog" fileName="mylog.log"
filePattern="mylog-%d{yyyyMMdd-HHmm}.rolled">
<PatternLayout>
<pattern>%d{ISO8601} [%t] %p - %m%n</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="100KB" />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="mylogger" level="debug" additivity="false">
<AppenderRef ref="mylog" />
</Logger>
<Root level="debug">
<AppenderRef ref="sysoutlog" />
</Root>
</Loggers>
</Configuration>
有关更多格式选项,请参阅Docs of layout configuration。 此外,如果您打算将根记录器转发到控制台,我会添加此appender
<Console name="STDOUT" target="SYSTEM_OUT" />
并将root logger的appender更改为
<AppenderRef ref="STDOUT" />