0

I would like to add to my log filename the date. For exemple if my filename is "jobfile", I will have "jobfile20170802". Below is my configuration file :

    log4j.rootLogger=debug, R
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=C:/TFS/PID/Dev/CRM/Logs/Dev/talend_crmJobs.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}| [%-5p]| %c{1} | %m%n
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
lemufty
  • 1
  • 1
  • 1
  • possible duplicate of https://stackoverflow.com/questions/192456/setting-a-log-file-name-to-include-current-date-in-log4j – user3849960 Aug 02 '17 at 12:26
  • 5
    Possible duplicate of [Setting a log file name to include current date in Log4j](https://stackoverflow.com/questions/192456/setting-a-log-file-name-to-include-current-date-in-log4j) – Tapaka Aug 02 '17 at 12:27

2 Answers2

0

Please try to using log4j.properties file. Also include apache-log4j-extras 1.1 in pom.xml with log4j 1.2.16

log4j.appender.LOGFILE=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.LOGFILE.RollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy
log4j.appender.LOGFILE.RollingPolicy.FileNamePattern=/logs/application_%d{yyyy-MM-dd}.log
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • hi thank you for your answer. but i'm error. this is error below: log4j:WARN No such property [rollingPolicy] in org.apache.log4j.RollingFileAppender. log4j:WARN File option not set for appender [rollingAppender]. log4j:WARN Are you using FileAppender instead of ConsoleAppender? log4j:ERROR No output stream or file set for the appender named [rollingAppender – lemufty Aug 03 '17 at 11:40
  • please add apache-log4j-extras-1.2.17.jar, if it is not in your build path and let me know if you are still facing issues. – DIksha Ahuja Aug 04 '17 at 03:37
0

I have following suggestion:

Make a change like following (although there could be problem in syntax):

log4j.appender.R.File=${logfilename}.log

Then in the code set logfilename by calling System.setProperty("logfilename", getCurrentDate In the format you need)

deepakl
  • 172
  • 8