[ 
https://issues.apache.org/jira/browse/LOG4J2-679?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14087913#comment-14087913
 ] 

Remko Popma commented on LOG4J2-679:
------------------------------------

How about, instead of looking at the return value of {{File.mkdirs()}}, we just 
check {{File.exists()}} again?

{code}
...
if (parent != null && !parent.exists()) { <-- parent.exists() might be false 
for multiple callers
  // multiple threads may call this method, only one of them will get result 
TRUE, so ignore the result
  parent.mkdirs();
  
  // it doesn't matter if it was this thread's call to mkdirs that succeeded
  // or some other thread, as long as the directory exists, we're happy.
  if (!parent.exists()) {
    LOGGER.error("Unable to create directory {}", parent.getAbsolutePath());
    return false;
  }
}
{code}

> Log rotation partly failed with error: "Unable to create directory ..."
> -----------------------------------------------------------------------
>
>                 Key: LOG4J2-679
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-679
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.0-rc1
>         Environment: JDK 1.6, tomcat 6, 
>            Reporter: Rene Schoenlein
>            Priority: Critical
>
> Log rotation partly failed with error: "Unable to create directory ..."
> I am using the following configuration (simplified for the purpose of this 
> ticket):
> {code}
> <Configuration status="info" name="App1" monitorInterval="60">
>   <Properties>
>     <Property name="defaultLayout">[%t %d{EEE MMM dd HH:mm:ss z yyyy} 
> &lt;%level{TRACE=6, DEBUG=5, INFO=4, WARN=3, ERROR=2, FATAL=1}&gt;] 
> %m%n</Property>
>     <Property name="patternCharset">UTF-8</Property>
>     <Property name="logDir">/var/log/app1/</Property>
>     <Property name="backupDir">/var/backups/app1/%d{yyyy}/%d{MM}/</Property>
>   </Properties>
>   <Appenders>
>     <RollingRandomAccessFile name="A" fileName="${logDir}A.log" 
> filePattern="${backupDir}A.log-%d{yyyyMMdd}">
>       <PatternLayout pattern="${defaultLayout}" charset="${patternCharset}"/>
>       <Policies>
>         <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
>       </Policies>
>     </RollingRandomAccessFile>
>     <RollingRandomAccessFile name="B" fileName="${logDir}B.log" 
> filePattern="${backupDir}B.log-%d{yyyyMMdd}">
>       <PatternLayout pattern="${defaultLayout}" charset="${patternCharset}"/>
>       <Policies>
>         <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
>       </Policies>
>     </RollingRandomAccessFile>
>     <!-- ... additional appenders, only differing in 
> appender-name/log-file-name, where removed for this ticket -->
>     <RollingRandomAccessFile name="C" fileName="${logDir}Y.log" 
> filePattern="${backupDir}Y.log-%d{yyyyMMdd}">
>       <PatternLayout pattern="${defaultLayout}" charset="${patternCharset}"/>
>       <Policies>
>         <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
>       </Policies>
>     </RollingRandomAccessFile>
>     <RollingRandomAccessFile name="D" fileName="${logDir}Z.log" 
> filePattern="${backupDir}Z.log-%d{yyyyMMdd}">
>       <PatternLayout pattern="${defaultLayout}" charset="${patternCharset}"/>
>       <Policies>
>         <TimeBasedTriggeringPolicy interval="1" modulate="true"/>
>       </Policies>
>     </RollingRandomAccessFile>
>   </Appenders>
>   <Loggers>
>     <Logger name="A" level="INFO" additivity="false">
>       <AppenderRef ref="A"/>
>     </Logger>
>     <Logger name="B" level="INFO" additivity="false">
>       <AppenderRef ref="B"/>
>     </Logger>
>     <!-- ... additional loggers, only differing in logger-name/appender-ref, 
> where removed for this ticket -->
>     <Logger name="C" level="INFO" additivity="false">
>       <AppenderRef ref="C"/>
>     </Logger>
>     <Logger name="D" level="INFO" additivity="false">
>       <AppenderRef ref="D"/>
>     </Logger>
>   </Loggers>
> </Configuration>
> {code}
> As part of last nights log-rotation, sub-folders "/2014/06/" had to be 
> created on top of the already existing "/var/backups/app1/" folder structure. 
> During this log-rotation task, 2 out of ~20 files (all constantly written by 
> the same application) where not rotated in the desired folder 
> "/var/backups/app1/2014/06/" but are still actively used in the base folder. 
> The only hint I could find regarding this issue was the following log output 
> from log4j (matching the rotation time):
> 2014-06-24 00:00:00,084 ERROR Unable to create directory 
> /var/backups/app1/2014/06
> 2014-06-24 00:00:00,084 ERROR Unable to create directory 
> /var/backups/app1/2014/06
> Strangely all other log-file where correctly rotated to the identical 
> destination directory. 
> Until now i was not able to reproduce this behavior in my testing environment 
> but i suspect that there might be an issue with handling multiple 
> log-rotations in parallel for a "to be created" sub-directory.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to