我想在selenium项目中的Log4J Java生成的日志文件中添加一个timeStamp(“app_logs_2023-05-15.log”),但没有实现

1wnzp6jl  于 2023-05-05  发布在  Java
关注(0)|答案(1)|浏览(120)

我尝试使用log4j.appender.file.File=logs/app_logs%d{yyyy-mm-dd}.log,但生成的文件名为“app_logs%d{yyyy-mm-dd}.log”。未添加时间戳。
还尝试了log4j.appender.FileNamePattern=logs/application_%d{yyyy-MM-dd}.log
任何建议将不胜感激。

log4j.rootLogger=INFO, file, stdout

# Direct log messages to a log file

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=logs/app_logs.log   =====\>\> Need to updated this.
log4j.appender.file.MaxFileSize=10KB
log4j.appender.file.Append=true
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout.ConversionPattern=\[%3p\] %d \[%t\] %c %x - %m%n

# Direct log messages to stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=\[%-p\] %d \[%t\] %c %x - %m%n
xmakbtuz

xmakbtuz1#

Maven dependecy:

<dependency>
            <groupId>log4j</groupId>
            <artifactId>apache-log4j-extras</artifactId>
            <version>1.2.17</version>
        </dependency>

log4j.properties:

# Root logger option
log4j.rootLogger=INFO, file, stdout

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.file.rollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy
log4j.appender.file.rollingPolicy.fileNamePattern=${user.home}\\myLogDirectory\\%d{yyyy-MM-dd}.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd.MM.yyyy HH:mm:ss.SSS}  [%t] %c{2}.%M %5p: %m%n
 
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{dd.MM.yyyy HH:mm:ss.SSS} [%t] %c{2}.%M %5p: %m%n

日志文件:

2023-05-03.log

相关问题