Class FileLogger


  • public class FileLogger
    extends Object
    This class can write log messages to log files. It is constructed with a log directory. In this directory, the file logger will automatically create log files. Each log file will get a name with the current date.
    • Field Detail

      • ARCHIVE_LOCK

        public static final Object ARCHIVE_LOCK
    • Constructor Detail

      • FileLogger

        public FileLogger​(File logDir)
                   throws IOException
        Constructs a new file logger. The specified log directory will be created if it doesn't already exist.
        Parameters:
        logDir - the log directory
        Throws:
        IOException - if the log directory can't be created
    • Method Detail

      • setArchiveDelay

        public void setArchiveDelay​(int days)
        Sets the number of days after which log files should be archived to a zip file. If you set "days" to 1, then it will archive yesterday's log file and older log files. If you set "days" to 0, then it won't archive any log files. The default is 0.
        Parameters:
        days - the number of days after which log files should be archived
      • setPurgeDelay

        public void setPurgeDelay​(int days)
        Sets the number of days after which log files should be purged. If you set "days" to 1, then it will purge yesterday's log file and older log files. If you set "days" to 0, then it won't purge any log files. The default is 0.
        Parameters:
        days - the number of days after which log files should be purged
      • printTaggedMessage

        public int printTaggedMessage​(int priority,
                                      String tag,
                                      org.joda.time.LocalDate date,
                                      String msg)
        Writes a log message. The lines in the message should already be tagged with the log level, message tag (identifies the source of the log message) and the current date and time. Every line should end with a new line character, including the last line. This method is thread safe.

        If the specified date has already been archived or purged, then this method has no effect.

        Parameters:
        priority - the log level
        tag - the message tag
        date - the date of the log message
        msg - the tagged message
        Returns:
        0 if no error occurred, an error code otherwise