I have tried with log4j.appender.file.File=logs/app_logs%d{yyyy-mm-dd}.log but file is getting generated with "app_logs%d{yyyy-mm-dd}.log" name. TimeStamp is not getting added.

Also tried with log4j.appender.FileNamePattern=logs/application_%d{yyyy-MM-dd}.log as well.

Any suggestion would be really appreciated.

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
1

There are 1 best solutions below

1
On

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

log file:

2023-05-03.log