Skip to content

Commit

Permalink
LOGBOX-79 #resolve
Browse files Browse the repository at this point in the history
new rolling appender property archiveLayout which is a closure that returns the pattern of the archive layout
  • Loading branch information
lmajano committed Nov 2, 2023
1 parent 27c0fe3 commit e9172e3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
21 changes: 20 additions & 1 deletion system/logging/appenders/RollingFileAppender.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,33 @@ component accessors="true" extends="coldbox.system.logging.appenders.FileAppende
setProperty( "fileMaxArchives", "10" );
}
if ( !propertyExists( "archiveLayout" ) ) {
setProperty( "archiveLayout", "" );
setProperty( "archiveLayout", variables.getDefaultArchiveLayout );
}

variables.fileRotator = new coldbox.system.logging.util.FileRotator();

return this;
}

/**
* Get the default archive layout:
* <code>#filename#-#yyy-mm-dd#-#hh-mm#-#archiveNumber#</code>
* DO NOT ADD EXTENSION TO IT, WE WILL ADD IT
*
* @filename The filename to use for the archive layout
* @archiveCount The archive count
*
* @return The default archive layout
*/
function getDefaultArchiveLayout( required filename, required archiveCount ){
return arguments.fileName &
"-" &
dateFormat( now(), "yyyy-mm-dd" ) &
"-" &
timeFormat( now(), "HH-mm" ) &
"-#arguments.archiveCount + 1#";
}

/**
* Called upon registration
*/
Expand Down
10 changes: 3 additions & 7 deletions system/logging/util/FileRotator.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,9 @@ component accessors="true" {
}

// Set the name of the archive
var zipFileName = getDirectoryFromPath( logFullPath ) &
fileName &
"-" &
dateFormat( now(), "yyyy-mm-dd" ) &
"-" &
timeFormat( now(), "HH-mm" ) &
"-#qArchivedLogs.recordcount + 1#" &
var archiveLayout = appender.getProperty( "archiveLayout" );
var zipFileName = getDirectoryFromPath( logFullPath ) &
archiveLayout( fileName, qArchivedLogs.recordcount ) &
".zip";

arguments.appender.lock( () => {
Expand Down

0 comments on commit e9172e3

Please sign in to comment.