Search code examples
javalogginglog4jlog4j2rollingfileappender

Log4j2 'Unable to move file' error when using RollingFileAppender with millisecond level rolling


I am trying to configure Log4j2 to roll and log files at a millisecond level granularity.

The configuration (relavant parts) I have used is as follows:

status=error

dest = err

property.filename = logs/dims/${env:HOSTNAME}/logging-${date:yyyy-MM-dd'T'HH:mm:ss,SSSSS}.log

appenders = console, rolling

## Rolling File Appender
appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.append = true
appender.rolling.fileName = ${filename}
appender.rolling.filePattern = logs/dims/${env:HOSTNAME}/logging-%d{yyyy-MM-dd'T'HH:mm:ss,SSSS}.log

appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy

rootLogger.level = info
rootLogger.appenderRefs = console, rolling

rootLogger.appenderRef.console.ref = STDOUT
rootLogger.appenderRef.rolling.ref = RollingFile

The log files are being created at the required granualarity but I see errors in the console as follows:

2019-06-10 10:57:41,689 main ERROR Unable to move file logs/dims/dsp/logging-2019-06-10T10:57:31,00358.log to logs/dims/dsp/logging-2019-06-10T10:57:41,0587.log: java.nio.file.NoSuchFileException logs/dims/dsp/logging-2019-06-10T10:57:31,00358.log -> logs/dims/dsp/logging-2019-06-10T10:57:41,0587.log

But the two files logging-2019-06-10T10:57:31,00358.log and logging-2019-06-10T10:57:41,0587.log in the error are present when I do an ls.

Can someone help me with understanding what is causing this error and how to prevent it?


Solution

  • I was running this on Ubuntu bash console for Windows 10. Although the bash console provides a Linux like interface I guess the acceptable characters in the file name is still decided by the underlying Windows system. The log files are getting created but the logger seems to be having problems rolling over to the new file because of the : in the filenames.

    Based on Vikas's comment, I ran the same code on a Linux machine and there were no errors then.