1

I need my current log to have the current date instead of only the name. So I need "vproxy_access.2016-01-10" instead of "vproxy_access".

<RollingRandomAccessFile name="ACCESS_LOG" 
             fileName="${sys:log.dir}vproxy_access.%d{${sys:log.dateformat}}"
             filePattern="${sys:log.dir}vproxy_access.%d{${sys:log.dateformat}}"
             append="true" 
             immediateFlush="false">

The "filePattern" is correctly applied when rotating the log, but not for a newly created log when I start Tomcat.

Remko Popma
  • 35,130
  • 11
  • 92
  • 114
JBalaguero
  • 181
  • 2
  • 13
  • I believe there may be an outstanding feature request for this on the Log4j2 JIRA issue tracker. – Remko Popma Jan 10 '17 at 22:48
  • https://issues.apache.org/jira/browse/LOG4J2/?selectedTab=com.atlassian.jira.jira-projects-plugin:issues-panel shows: Tab panel 'com.atlassian.jira.jira-projects-plugin:issues-panel' failed to render. – JBalaguero Jan 12 '17 at 09:46
  • FYI, the JIRA issue has been resolved. – Remko Popma Jan 14 '17 at 11:24

3 Answers3

1

This will be available in Log4j 2.8.

See https://issues.apache.org/jira/browse/LOG4J2-1101

Remko Popma
  • 35,130
  • 11
  • 92
  • 114
  • Great Remko! Our current implementation makes impossible to use log4j2 without this feature, so we had to move back to log4j. Is there any timeline for log4j 2.8? Thanks. – JBalaguero Jan 16 '17 at 10:51
  • No date set. Depends on who wants to do the release work & when they have time. Doing a release takes a whole day currently. – Remko Popma Jan 16 '17 at 11:14
  • 1
    I have performed most of the release builds. I'm hopeful it will happen in the next few weeks. – rgoers Jan 17 '17 at 04:28
  • Today I have tried log4j 2.8.1 to check that the name is no longer necessary, and it seems to be fixed with RollingFile but not with RollingRandomAccessFile. Tomcat shows this error starting our app: ERROR No filename was provided for FileAppender with name ACCESS_LOG. Is this possible or I'm forgetting something? – JBalaguero Apr 14 '17 at 17:02
  • I think there's a JIRA to also support this for RollingRandomAccessFile. Hard to say anything about the error you are seeing without knowing your configuration. Best to follow up on JIRA or the mailing list. – Remko Popma Apr 14 '17 at 18:38
  • Yes, Log4j 2LOG4J2-1878Dates in filename for RollingRandomAccessFile appender. I suppose that next version of log4j2 will take some time, so I'll move back to log4j again. Is the peformance difference between RollingFile and RollingRandomAccessFile very big? – JBalaguero Apr 15 '17 at 09:18
  • Recently the difference is less than it used to be. We sped up FileAppender. See https://logging.apache.org/log4j/2.x/performance.html#fileLoggingComparison for comparison with Log4j-1.2 (hint: no contest) and https://logging.apache.org/log4j/2.x/performance.html#tradeoffs for RAF vs File. – Remko Popma Apr 15 '17 at 11:46
1

I had a similar problem today and I found this solution on how to append the current date to the file name of a newly created log file.

The accepted answer of the linked question gives following configuration example:

<RollingFile name="RollingFile" fileName="${log-path}/filename.log" 
filePattern="${log-path}/filename-%d{yyyy-MM-dd}-%i.log" >
...
...
</RollingFile>

This worked for me, I hope it helps you (or other people with the same problem) as well.

xoX Zeus Xox
  • 195
  • 1
  • 14
0

I think i can help u with following:

fileName="${sys:log.dir}vproxy_access.${date:${sys:log.dateformat}}"
Z.min
  • 21
  • 2
  • in addtion, if your first newly created log is not correct, and from the next it' ok. then i guess your System.setProperty("log.dateformat", "value") later than the first log create, you need to configurate log4j2 programmingly. – Z.min Jul 19 '17 at 01:03