Class FileHandler

  • All Implemented Interfaces:
    Comparable<Handler>
    Direct Known Subclasses:
    RotatingFileHandler

    public class FileHandler
    extends AbstractLogHandler
    Sends all logging output to the specified log file.
    Makes use of the ADAMS_LOGFILE_PREFIX environment variable. E.g., with "ADAMS_LOGFILE_PREFIX=testing-", the default log file "$HOME/.adams/log/console.log" will become "$HOME/.adams/log/testing-console.log".
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Field Detail

      • ADAMS_LOGFILE_PREFIX

        public static final String ADAMS_LOGFILE_PREFIX
        the environment variable to inject a prefix into the log file.
        See Also:
        Constant Field Values
      • m_LogFile

        protected File m_LogFile
        the log file to use.
      • m_LogIsDir

        protected boolean m_LogIsDir
        whether the file points to a directory.
    • Constructor Detail

      • FileHandler

        public FileHandler()
    • Method Detail

      • setLogFile

        public void setLogFile​(File value)
        Sets the log file to use.
        Parameters:
        value - the file
      • getLogFile

        public File getLogFile()
        Returns the log file in use.
        Returns:
        the file
      • setUp

        protected void setUp()
        Hook method for performing setup before processing first log record.
        Overrides:
        setUp in class AbstractLogHandler
      • doPublish

        protected void doPublish​(LogRecord record)
        Publish a LogRecord.

        The logging request was made initially to a Logger object, which initialized the LogRecord and forwarded it here.

        The Handler is responsible for formatting the message, when and if necessary. The formatting should include localization.

        Specified by:
        doPublish in class AbstractLogHandler
        Parameters:
        record - description of the log event. A null record is silently ignored and is not published
      • compareTo

        public int compareTo​(Handler o)
        Compares the handler with itself.
        Specified by:
        compareTo in interface Comparable<Handler>
        Overrides:
        compareTo in class AbstractLogHandler
        Parameters:
        o - the other handler
        Returns:
        less than 0, equal to 0, or greater than 0 if the handler is less, equal to, or greater than this one