java.lang.Object
net.i2p.util.LogWriter
net.i2p.util.FileLogWriter
All Implemented Interfaces:
Runnable

class FileLogWriterextends LogWriter
File-based log writer thread that pulls log records from the LogManager, writes them to the current logfile, and rotates the logs as necessary.
  • Field Details

    • _currentOut

      private volatile Writer _currentOut
      The writer for the current log file, volatile as it changes on rotation.
    • _rotationNum

      private int _rotationNum
      Number of the current rotation.
    • _currentFile

      private File _currentFile
      The file being written now.
    • _numBytesInCurrentFile

      private long _numBytesInCurrentFile
      Bytes written to the current file.
    • _groupReadable

      private boolean _groupReadable
      True to make the log files group readable.
    • MAX_DISKFULL_MESSAGES

      private static final int MAX_DISKFULL_MESSAGES
      Most disk full errors logged.
      See Also:
    • _diskFullMessageCount

      private int _diskFullMessageCount
      Disk full errors logged so far.
  • Constructor Details

    • FileLogWriter

      public FileLogWriter(LogManager manager)
      Creates a writer that drains log records to rotating files on disk.
      Parameters:
      manager - the LogManager this writer drains records from; its configuration supplies the log directory and rotation settings
  • Method Details

    • currentFile

      public String currentFile()
      File may not exist or have old logs in it if not opened yet.
      Specified by:
      currentFile in class LogWriter
      Returns:
      non-null
    • isGroupTraversable

      static boolean isGroupTraversable(File dir)
      Whether the group can traverse (search) an existing directory. Group execute on the directory is what allows a group-readable file inside it to be opened, so this is the check that decides whether group-readable log files are actually reachable.
      Parameters:
      dir - the directory to test
      Returns:
      true if the group has execute/search permission, or if permissions cannot be determined
    • writeRecord

      protected void writeRecord(LogRecord rec, String formatted)
      Write the record and its formatted text, using the record's priority.
      Specified by:
      writeRecord in class LogWriter
      Parameters:
      rec - the LogRecord to write.
      formatted - a String pre-formatted from rec, may be ignored.
    • writeRecord

      protected void writeRecord(int priority, String val)
      Write the formatted record text at the given priority.
      Specified by:
      writeRecord in class LogWriter
      Parameters:
      priority - the level to log the line at.
      val - the String to write.
    • flushWriter

      protected void flushWriter()
      Flush the log file writer.
      Specified by:
      flushWriter in class LogWriter
    • closeWriter

      protected void closeWriter()
      Close the log file writer.
      Specified by:
      closeWriter in class LogWriter
    • closeWriter

      private void closeWriter(File currentFile, boolean threadGzipper)
      Gzip the closed file.
      Parameters:
      currentFile - the log file just closed, gzipped if it is large enough
      threadGzipper - if true, spin off a thread
    • rotateFile

      private void rotateFile()
      Rotate to the next file (or the first file if this is the first call)

      Caller must synch.

    • getNextFile

      private File getNextFile()
      Next file in the rotation.

      Caller must sync.

      Returns:
      the next file
    • getFirstFile

      private File getFirstFile(File base, String pattern, int max)
      Retrieve the first file, updating the rotation number accordingly

      Caller must synch.

      Parameters:
      base - the log directory the file name is resolved against, null if the pattern is a full path
      pattern - the file name pattern where each # or @ is replaced by the rotation number
      max - the maximum number of rotation files
      Returns:
      the first rotation file that does not exist yet, or the oldest one if all of them exist
    • replace

      private static final String replace(String pattern, int num)
      Puts the rotation number into the file name.
      Parameters:
      pattern - the name with a hash placeholder
      num - the rotation number
      Returns:
      the file name