You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by bu...@apache.org on 2002/06/05 21:26:51 UTC

DO NOT REPLY [Bug 9645] New: - Add rolloverPath attribute to DailyRollingFileAppender

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9645>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9645

Add rolloverPath attribute to DailyRollingFileAppender

           Summary: Add rolloverPath attribute to DailyRollingFileAppender
           Product: Log4j
           Version: 1.2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Appender
        AssignedTo: log4j-dev@jakarta.apache.org
        ReportedBy: jeff.stickel@seurat.com


I would like to suggest a new attribute "rolloverPath" be added to the 
DailyRollingFileAppender class.  In short, the rolloverPath (configurable via a 
property) could point to a new location to which rolled-over files could be 
copied.  The code samples below illustrate how we have implemented this 
feature.  For brevity�s sake, I�ve included code snippets instead of the entire 
org.apache.log4j.DailyRollingFileAppender.java file that we've enhanced.  The 
sample code should be read in the context of Log4J 1.2.2 
DailyRollingFileAppender.java source.

First, I added the following Javadoc:
* <p>An optional <code>rolloverPath</code> may be specified such 
* that files that are rolled over will be created in the location
* specified by this path.  Any parent path information in the original
* logfile name is ignored when the rollover occurs. 
* <code>rolloverPath</code> may be absolute or relative. 
*
* If in the previous example the <code>rolloverPath</code> is set to 
* <code>/archive</code>, the logging file <code>/foo/bar.log</code>
* will be copied to <code>/archive/bar.log.2001-02-16</code> and 
* logging will continue normally.
*/


Added new attributes:
/**
 * Pathname and directory (File object) used if files are to archive to
 * a different location than where the lof file is created.
 */
private String rolloverPath;
private File rolloverDir;

    
Added a new constructor:
/**
 * Instantiate a <code>DailyRollingFileAppender</code> and open the
 * file designated by <code>filename</code>.  Files that are rolled 
 * over are archived to the location specified by the
 * <code>rolloverPath</code>
 */
public DailyRollingFileAppender(Layout layout, String rolloverPath, 
  String filename, String datePattern)
                                                 throws IOException {
    this( layout, filename, datePattern );
        
    setRolloverPath( rolloverPath );
}

Also added the setRolloverPath() method:
/**
 * Sets the location to which log files will be rolled over .  If the
 * given path already exists, it must be writable and must be a
 * directory.  If it doesn't exist, it will get created, along with any
 * necessary, non-existent parent directories.
 */
public void setRolloverPath( String pathName ) {
    rolloverPath = pathName;
    rolloverDir = new File( rolloverPath );

    // Check to see if the rollover path exists (needs to be created) 
    // and if we can write to it.
    if ( rolloverDir.exists() ) {
        if ( !rolloverDir.isDirectory() ) {
            LogLog.warn( "The path name " + pathName + " does not refer to a 
directory." );
            rolloverDir = null;
        }
        else if ( !rolloverDir.canWrite() ){
            LogLog.warn( "Unable to write to directory " + 
  rolloverDir.getAbsolutePath() );
            rolloverDir = null;
        }
            
    }
    else if ( !rolloverDir.mkdirs() ) {
        LogLog.warn( "Unable to create rollover directory for " + 
    rolloverPath );
        rolloverDir = null;
    }
}


Updated the rollover() method:
.
.
.
/* If rolloverDir was specified, ignore any path information in
 * the original filename and use the rolloverPath instead. */
// File target  = new File(scheduledFilename); // Original code
File target;
if ( rolloverDir == null ) {
    target = new File( scheduledFilename );
}
else {
    target = new File( rolloverDir, 
                      (new File(scheduledFilename)).getName() );
}
.
.
.    
//LogLog.debug(fileName +" -> "+ scheduledFilename); // Original code
LogLog.debug(fileName +" -> "+ target.getPath());
.
.
.

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>