我有静态日志文件名“CRM_Update_dubg_Logs.log”的xml配置文件,我想用时间戳创建这个名称,java log4j 2.9.1
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS}{GMT+3} [%t] %-5level
%logger{36} - %msg%n" />
</Console>
<File name="MyFile" fileName="CRM_Update_Logs.log" immediateFlush="true" append="true">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS}{GMT+3} %c{2} [%t] %-5level %logger{36} - %msg%n"/>
</File>
<File name="dubg_Logs" fileName="CRM_Update_dubg_Logs.log" immediateFlush="true" append="true">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS}{GMT+3} %c{2} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console"/>
<AppenderRef ref="MyFile"/>
<AppenderRef ref="dubg_Logs"/>
</Root>
<Logger level="ALL" additivity="false" name="dubg">
<AppenderRef ref="dubg_Logs"/>
</Logger>
</Loggers>
答案 0 :(得分:0)
在xml中编辑文件名
fileName="CRM_Update_Logs.log"
是
fileName="${sys:logFilename}_CRM_Update_Logs.log"
并将其添加到您的Java代码
Date date = new Date();
String LogDate= new SimpleDateFormat("yyyyMMdd").format(date);
System.setProperty("logFilename", LogDate);