public class StartupTriggeringPolicy<E> extends ch.qos.logback.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy<E>
Credit for the initial implementation belongs to this StackOverflow post.
Constructor and Description |
---|
StartupTriggeringPolicy() |
Modifier and Type | Method and Description |
---|---|
private java.lang.Runnable |
asyncCleanFiles(int keep,
java.io.File[] files)
Creates a thread that attempts to remove all but the
keep oldest
files in files (by using the last modified times). |
private java.lang.Runnable |
asyncCleanReallyOldFiles()
Removes log files archived by a very preliminary version of our Logback
configuration.
|
private java.lang.Runnable |
asyncClearFiles(java.io.File oldDirectory,
java.io.File newDirectory,
java.io.File[] files)
Moves all files within
oldDirectory into newDirectory ,
and then removes oldDirectory . |
private void |
cleanupArchivedLogs(int keepFiles)
Finds the archived log files and determines whether or not
asyncCleanFiles(int, java.io.File[])
should be called (and if it should, this method calls it). |
private void |
removeOldLogDirectory(java.io.File oldDirectory,
java.io.File newDirectory)
Fires off a thread that moves all files within
oldDirectory
into newDirectory , and then attempts to remove
oldDirectory . |
private void |
removePath(java.nio.file.Path pathToRemove)
Convenience method that attempts to delete
pathToRemove . |
private void |
renameOldLogDirectory()
Responsible for determining what to do about the "logs" and
"archived_logs" subdirectory situation.
|
void |
start()
Triggers a "logback rollover" and calls
cleanupArchivedLogs(int) . |
isTriggeringEvent, toString
computeNextCheck, getArchiveRemover, getCurrentPeriodsFileNameWithoutCompressionSuffix, getCurrentTime, getElapsedPeriodsFileName, isErrorFree, isStarted, setCurrentTime, setDateInCurrentPeriod, setDateInCurrentPeriod, setTimeBasedRollingPolicy, stop
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
public StartupTriggeringPolicy()
private void renameOldLogDirectory()
private void removeOldLogDirectory(java.io.File oldDirectory, java.io.File newDirectory)
oldDirectory
into newDirectory
, and then attempts to remove
oldDirectory
.oldDirectory
- "Old" log file directory. Be aware that
any files within this directory will be relocated to
newDirectory
and this directory will then be removed. Cannot be
null
.newDirectory
- Destination for any files within
oldDirectory
. Cannot be null
.private java.lang.Runnable asyncClearFiles(java.io.File oldDirectory, java.io.File newDirectory, java.io.File[] files)
oldDirectory
into newDirectory
,
and then removes oldDirectory
.oldDirectory
- "Old" log file directory. Cannot be
null
.newDirectory
- "New" log file directory. Cannot be
null
.files
- {link File Files} within oldDirectory
that should
be moved to newDirectory
. Cannot be null
.oldDirectory
to newDirectory
and then attempt removal
of oldDirectory
. Be aware that this thread has not yet had
"start" called.private void cleanupArchivedLogs(int keepFiles)
asyncCleanFiles(int, java.io.File[])
should be called (and if it should, this method calls it).keepFiles
- Number of archived log files to keep around.private java.lang.Runnable asyncCleanReallyOldFiles()
private void removePath(java.nio.file.Path pathToRemove)
pathToRemove
.pathToRemove
- Path
to the file to delete.
Cannot be null
.private java.lang.Runnable asyncCleanFiles(int keep, java.io.File[] files)
keep
oldest
files in files
(by using the last modified times).keep
- Number of archived log files to keep around.files
- Archived log files. Cannot be null
.public void start()
cleanupArchivedLogs(int)
.start
in interface ch.qos.logback.core.spi.LifeCycle
start
in class ch.qos.logback.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy<E>