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, dateInCurrentPeriod, elapsedPeriodsFileName, errorFree, nextCheck, rc, started, tbrp

    Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase

    context
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private Runnable
    asyncCleanFiles(int keep, File[] files)
    Creates a thread that attempts to remove all but the keep oldest files in files (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 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(File oldDirectory, File newDirectory)
    Fires off a thread that moves all files within oldDirectory into newDirectory, and then attempts to remove oldDirectory.
    private void
    removePath(Path pathToRemove)
    Convenience method that attempts to delete pathToRemove.
    private void
    Responsible for determining what to do about the "logs" and "archived_logs" subdirectory situation.
    void
    Triggers a "logback rollover" and calls cleanupArchivedLogs(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, 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
  • Constructor Details

  • Method Details

    • renameOldLogDirectory

      private void renameOldLogDirectory()
      Responsible for determining what to do about the "logs" and "archived_logs" subdirectory situation.
    • removeOldLogDirectory

      private void removeOldLogDirectory(File oldDirectory, File newDirectory)
      Fires off a thread that moves all files within oldDirectory into newDirectory, and then attempts to remove oldDirectory.
      Parameters:
      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.
    • asyncClearFiles

      private Runnable asyncClearFiles(File oldDirectory, File newDirectory, File[] files)
      Moves all files within oldDirectory into newDirectory, and then removes oldDirectory.
      Parameters:
      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.
      Returns:
      Thread that will attempt to relocate any files within oldDirectory to newDirectory and then attempt removal of oldDirectory. Be aware that this thread has not yet had "start" called.
    • cleanupArchivedLogs

      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).
      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

      private void removePath(Path pathToRemove)
      Convenience method that attempts to delete pathToRemove.
      Parameters:
      pathToRemove - Path to the file to delete. Cannot be null.
    • asyncCleanFiles

      private Runnable asyncCleanFiles(int keep, File[] files)
      Creates a thread that attempts to remove all but the keep oldest files in files (by using the last modified times).
      Parameters:
      keep - Number of archived log files to keep around.
      files - Archived log files. Cannot be null.
      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

      public void start()
      Triggers a "logback rollover" and calls cleanupArchivedLogs(int).
      Specified by:
      start in interface ch.qos.logback.core.spi.LifeCycle
      Overrides:
      start in class ch.qos.logback.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy<E>