Bug 56019

Summary: RollingFileAppender not working if destination directory does not exists
Product: Log4j - Now in Jira Reporter: Roberto <roberjruiz>
Component: OtherAssignee: log4j-dev <log4j-dev>
Status: NEW ---    
Severity: minor    
Priority: P2    
Version: 1.2.17   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description Roberto 2014-01-16 12:54:11 UTC
I am using RollingFileAppender with TimeBasedRollingPolicy. I'd like backup files to be saved in a different folder than the current one.

The problem I am having, is that it only works when destination directory of backup files is already created. When backup directory does not exists, then rollover is skipped.

I debugged code and realized that the problem may be solved if the backup folder is created in FileRenameAction

Just change the method execute in FileRenameAction to:

  public static boolean execute(
    final File source, final File destination, boolean renameEmptyFiles) {
    if (renameEmptyFiles || (source.length() > 0)) {
    	File destinationParent = destination.getParentFile();
    	if (!destinationParent.exists()) {
      return source.renameTo(destination);

    return source.delete();