Package edu.wisc.ssec.mcidasv.util
Class StartupTriggeringPolicy<E>
java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.rolling.TimeBasedFileNamingAndTriggeringPolicyBase<E>
ch.qos.logback.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy<E>
edu.wisc.ssec.mcidasv.util.StartupTriggeringPolicy<E>
- All Implemented Interfaces:
ch.qos.logback.core.rolling.TimeBasedFileNamingAndTriggeringPolicy<E>,ch.qos.logback.core.rolling.TriggeringPolicy<E>,ch.qos.logback.core.spi.ContextAware,ch.qos.logback.core.spi.LifeCycle
public class StartupTriggeringPolicy<E>
extends ch.qos.logback.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy<E>
This is a Logback "triggering policy" that forces a log
"roll" upon starting McIDAS-V. This policy will also attempt to
move the old "log" directory to "archived_logs" as well
as attempting to remove the oldest "archived log files".
Credit for the initial implementation belongs to this StackOverflow post.
-
Field Summary
Fields inherited from class ch.qos.logback.core.rolling.TimeBasedFileNamingAndTriggeringPolicyBase
archiveRemover, artificialCurrentTime, atomicNextCheck, dateInCurrentPeriod, elapsedPeriodsFileName, errorFree, rc, started, tbrpFields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate RunnableasyncCleanFiles(int keep, File[] files) Creates a thread that attempts to remove all but thekeepoldest files infiles(by using the last modified times).private RunnableRemoves log files archived by a very preliminary version of our Logback configuration.private RunnableasyncClearFiles(File oldDirectory, File newDirectory, File[] files) Moves all files withinoldDirectoryintonewDirectory, and then removesoldDirectory.private voidcleanupArchivedLogs(int keepFiles) Finds the archived log files and determines whether or notasyncCleanFiles(int, java.io.File[])should be called (and if it should, this method calls it).private voidremoveOldLogDirectory(File oldDirectory, File newDirectory) Fires off a thread that moves all files withinoldDirectoryintonewDirectory, and then attempts to removeoldDirectory.private voidremovePath(Path pathToRemove) Convenience method that attempts to deletepathToRemove.private voidResponsible for determining what to do about the "logs" and "archived_logs" subdirectory situation.voidstart()Triggers a "logback rollover" and callscleanupArchivedLogs(int).Methods inherited from class ch.qos.logback.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy
isTriggeringEvent, toStringMethods inherited from class ch.qos.logback.core.rolling.TimeBasedFileNamingAndTriggeringPolicyBase
computeNextCheck, getArchiveRemover, getCurrentPeriodsFileNameWithoutCompressionSuffix, getCurrentTime, getElapsedPeriodsFileName, isErrorFree, isStarted, setCurrentTime, setDateInCurrentPeriod, setTimeBasedRollingPolicy, stop, withErrorsMethods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContextMethods inherited from interface ch.qos.logback.core.rolling.TriggeringPolicy
getLengthCounter
-
Constructor Details
-
StartupTriggeringPolicy
public StartupTriggeringPolicy()
-
-
Method Details
-
renameOldLogDirectory
Responsible for determining what to do about the "logs" and "archived_logs" subdirectory situation. -
removeOldLogDirectory
Fires off a thread that moves all files withinoldDirectoryintonewDirectory, and then attempts to removeoldDirectory.- Parameters:
oldDirectory- "Old" log file directory. Be aware that any files within this directory will be relocated tonewDirectoryand this directory will then be removed. Cannot benull.newDirectory- Destination for any files withinoldDirectory. Cannot benull.
-
asyncClearFiles
Moves all files withinoldDirectoryintonewDirectory, and then removesoldDirectory.- Parameters:
oldDirectory- "Old" log file directory. Cannot benull.newDirectory- "New" log file directory. Cannot benull.files- {link File Files} withinoldDirectorythat should be moved tonewDirectory. Cannot benull.- Returns:
- Thread that will attempt to relocate any files within
oldDirectorytonewDirectoryand then attempt removal ofoldDirectory. Be aware that this thread has not yet had "start" called.
-
cleanupArchivedLogs
Finds the archived log files and determines whether or notasyncCleanFiles(int, java.io.File[])should be called (and if it should, this method calls it).- Parameters:
keepFiles- Number of archived log files to keep around.
-
asyncCleanReallyOldFiles
Removes log files archived by a very preliminary version of our Logback configuration. These files reside within the userpath, and are named "mcidasv.1.log.zip", "mcidasv.2.log.zip", and "mcidasv.3.log.zip".- Returns:
- Thread that will attempt to remove the three archived log files.
-
removePath
Convenience method that attempts to deletepathToRemove.- Parameters:
pathToRemove-Pathto the file to delete. Cannot benull.
-
asyncCleanFiles
Creates a thread that attempts to remove all but thekeepoldest files infiles(by using the last modified times).- Parameters:
keep- Number of archived log files to keep around.files- Archived log files. Cannot benull.- Returns:
- Thread that will attempt to remove everything except the specified number of archived log files. Be aware that this thread has not yet had "start" called.
-
start
Triggers a "logback rollover" and callscleanupArchivedLogs(int).- Specified by:
startin interfacech.qos.logback.core.spi.LifeCycle- Overrides:
startin classch.qos.logback.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy<E>
-