我使用log4j 2.8.1
我有这个log4j2.xml
文件
<Configuration status="warn" name="MyAppx" packages="">
<Appenders>
<RollingFile append="true" name="MyFile" fileName="/tmp/app.log" filePattern="/var/log/myLogs/app-%d{MM-dd-yyyy}-%i.log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} s7tcp %-5level %-30notEmpty{[%marker]} - %msg%xEx - %class{36} %L %M%n"/>
<Policies>
<SizeBasedTriggeringPolicy size="2 MB"/>
</Policies>
<DefaultRolloverStrategy max="20"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="INFO" includeLocation="true">
<AppenderRef ref="MyFile" />
</Root>
</Loggers>
我记录到/tmp/app.log
,如果文件大于2MB
,则应将其移至/var/log/myLogs/app-%d{MM-dd-yyyy}-%i.log
但是我收到此错误消息:
2017-04-03 10:30:00,874 Thread-3 ERROR Unable to move file /tmp/app.log to /var/log/myLogs/app-04-03-2017-19.log: java.nio.file.AtomicMoveNotSupportedException /tmp/app.log -> /var/log/myLogs/app-04-03-2017-19.log: Invalid cross-device link
2017-04-03 10:30:12,107 Thread-3 ERROR Unable to move file /tmp/app.log to /var/log/myLogs/app-04-03-2017-20.log: java.nio.file.AtomicMoveNotSupportedException /tmp/app.log -> /var/log/myLogs/app-04-03-2017-20.log: Invalid cross-device link
2017-04-03 10:30:23,396 Thread-3 ERROR Unable to move file /tmp/app.log to /var/log/myLogs/app-04-03-2017-20.log: java.nio.file.AtomicMoveNotSupportedException /tmp/app.log -> /var/log/myLogs/app-04-03-2017-20.log: Invalid cross-device link
2017-04-03 10:30:34,624 Thread-3 ERROR Unable to move file /tmp/app.log to /var/log/myLogs/app-04-03-2017-20.log: java.nio.file.AtomicMoveNotSupportedException /tmp/app.log -> /var/log/myLogs/app-04-03-2017-20.log: Invalid cross-device link
实际上只创建了第一个文件-1.log
,当我停止java进程时创建了所有其他文件!
如果filePattern
中的路径也在/tmp/...
上,那就可以正常使用了!
任何想法可能是什么问题?