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, tbrp
Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate Runnable
asyncCleanFiles
(int keep, File[] files) Creates a thread that attempts to remove all but thekeep
oldest files infiles
(by using the last modified times).private Runnable
Removes log files archived by a very preliminary version of our Logback configuration.private Runnable
asyncClearFiles
(File oldDirectory, File newDirectory, File[] files) Moves all files withinoldDirectory
intonewDirectory
, and then removesoldDirectory
.private void
cleanupArchivedLogs
(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 void
removeOldLogDirectory
(File oldDirectory, File newDirectory) Fires off a thread that moves all files withinoldDirectory
intonewDirectory
, and then attempts to removeoldDirectory
.private void
removePath
(Path pathToRemove) Convenience method that attempts to deletepathToRemove
.private void
Responsible for determining what to do about the "logs" and "archived_logs" subdirectory situation.void
start()
Triggers a "logback rollover" and callscleanupArchivedLogs(int)
.Methods inherited from class ch.qos.logback.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy
isTriggeringEvent, toString
Methods inherited from class ch.qos.logback.core.rolling.TimeBasedFileNamingAndTriggeringPolicyBase
computeNextCheck, getArchiveRemover, getCurrentPeriodsFileNameWithoutCompressionSuffix, getCurrentTime, getElapsedPeriodsFileName, isErrorFree, isStarted, setCurrentTime, setDateInCurrentPeriod, setTimeBasedRollingPolicy, stop, withErrors
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
Methods 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 withinoldDirectory
intonewDirectory
, and then attempts to removeoldDirectory
.- Parameters:
oldDirectory
- "Old" log file directory. Be aware that any files within this directory will be relocated tonewDirectory
and this directory will then be removed. Cannot benull
.newDirectory
- Destination for any files withinoldDirectory
. Cannot benull
.
-
asyncClearFiles
Moves all files withinoldDirectory
intonewDirectory
, and then removesoldDirectory
.- Parameters:
oldDirectory
- "Old" log file directory. Cannot benull
.newDirectory
- "New" log file directory. Cannot benull
.files
- {link File Files} withinoldDirectory
that should be moved tonewDirectory
. Cannot benull
.- Returns:
- Thread that will attempt to relocate any files within
oldDirectory
tonewDirectory
and 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
-Path
to the file to delete. Cannot benull
.
-
asyncCleanFiles
Creates a thread that attempts to remove all but thekeep
oldest 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:
start
in interfacech.qos.logback.core.spi.LifeCycle
- Overrides:
start
in classch.qos.logback.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy<E>
-