log4j2 - RollingFileAppender - Invalid cross-device link
Asked Answered
R

0

6

I use log4j 2.8.1 I have this log4j2.xml file

<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>

I do logging to /tmp/app.log and if the file gets bigger than 2MB it should be moved to /var/log/myLogs/app-%d{MM-dd-yyyy}-%i.log

but I get this error Messages:

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

only the First file -1.log is actually created, all other files are created when I stop the java process!

If the path in filePattern is also on /tmp/... it works just fine!

Any Idea what the problem could be?

Role answered 3/4, 2017 at 8:35 Comment(1)
I think this is because /tmp/ and /var/log/ are on separate file systems. Does the same issue happen when fileName="" is also on /var/ ?Eldwen

© 2022 - 2024 — McMap. All rights reserved.