Bug 56019 - RollingFileAppender not working if destination directory does not exists
Summary: RollingFileAppender not working if destination directory does not exists
Status: NEW
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.2.17
Hardware: PC Windows XP
: P2 minor
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-16 12:54 UTC by Roberto
Modified: 2014-01-16 12:54 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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()) {
    		destinationParent.mkdirs();
    	}
      return source.renameTo(destination);
    }

    return source.delete();
  }