ksl
ksl

Reputation: 4709

Error adding timestamp to log file name (log4j2)

I'm trying to configure log4j2 to add a timestamp to the log file as follows:

<File name="LogFile" 
      fileName="log/filename.log"
      filePattern="log/filename-%d{yyyy-mm-dd}.log">
</File>

but the following error is reported:

ERROR File contains an invalid element or attribute "filePattern"

If I remove the filePattern attribute a log file called filename.log is successfully created.

What am I doing wrong?

Upvotes: 1

Views: 718

Answers (1)

rgoers
rgoers

Reputation: 9141

The FileAppender only accepts a file name, not a pattern. You can use a lookup to get the date if that is what you want.

Upvotes: 1

Related Questions