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

abstract class LogWriterextends Object implements Runnable
Log writer thread that pulls log records from the LogManager and writes them to the log. This also periodically instructs the LogManager to reread its config file.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private long
    Timestamp of the first record displayed.
    private long
    The current interval between the flushes, in milliseconds.
    private LogRecord
    The last record displayed.
    private long
    Timestamp of last config reread.
    protected final LogManager
    The log manager owning this writer and its context.
    protected boolean
    Whether the writer should continue writing.
    private static final boolean
    Whether the displayed buffer shows newest first, false for oldest first.
    private static final String
    Bundle of the common translated strings.
    private static final long
    Every 10 seconds? Why? Just have the gui force a reread after a change??
    (package private) static final long
    Ajax refresh interval.
    private static final long
    Longest interval between the flushes.
    private static final long
    Shortest interval between the flushes.
    private static final String
    Bundle of the router translated strings.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new LogWriter.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    Close the writer.
    abstract String
    File may not exist or have old logs in it if not opened yet.
    private String
    dupMessage(int dupCount, LogRecord lastRecord, boolean reverse, boolean html)
    Return a msg with the date stamp of the last duplicate.
    void
    Flush pending log records.
    void
    flushRecords(boolean shouldWait)
    Flush pending log records, optionally waiting for new ones.
    protected abstract void
    Flush the writer output.
    private String
    ngettext(String b, String c, int a)
    Choose the singular or plural form for a translated count.
    private void
    Re-reads the display settings from the config.
    void
    run()
    Write loop, flushing records and rereading config until stopped.
    void
    setFlushInterval(long interval)
    Flush interval for the log writer, clamped to the supported range.
    void
    Stop the log writer thread.
    void
    Wake up the writer to immediately re-read config and flush pending records.
    private void
    writeDupMessage(int dupCount, LogRecord lastRecord)
    Write a msg with the date stamp of the last duplicate.
    protected abstract void
    writeRecord(int priority, String line)
    Write a single String verbatim to the writer.
    private void
    Writes one record to the log file.
    protected abstract void
    writeRecord(LogRecord rec, String formatted)
    Write the provided LogRecord to the writer.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CONFIG_READ_INTERVAL

      private static final long CONFIG_READ_INTERVAL
      Every 10 seconds? Why? Just have the gui force a reread after a change??
      See Also:
    • FLUSH_INTERVAL

      static final long FLUSH_INTERVAL
      Ajax refresh interval.
      See Also:
    • MIN_FLUSH_INTERVAL

      private static final long MIN_FLUSH_INTERVAL
      Shortest interval between the flushes.
      See Also:
    • MAX_FLUSH_INTERVAL

      private static final long MAX_FLUSH_INTERVAL
      Longest interval between the flushes.
      See Also:
    • BUFFER_DISPLAYED_REVERSE

      private static final boolean BUFFER_DISPLAYED_REVERSE
      Whether the displayed buffer shows newest first, false for oldest first.
      See Also:
    • _lastReadConfig

      private volatile long _lastReadConfig
      Timestamp of last config reread.
    • _manager

      protected final LogManager _manager
      The log manager owning this writer and its context.
    • _write

      protected volatile boolean _write
      Whether the writer should continue writing.
    • _last

      private LogRecord _last
      The last record displayed.
    • _firstTimestamp

      private long _firstTimestamp
      Timestamp of the first record displayed.
    • _flushInterval

      private volatile long _flushInterval
      The current interval between the flushes, in milliseconds.
    • BUNDLE_NAME

      private static final String BUNDLE_NAME
      Bundle of the common translated strings.
      See Also:
    • ROUTER_BUNDLE_NAME

      private static final String ROUTER_BUNDLE_NAME
      Bundle of the router translated strings.
      See Also:
  • Constructor Details

    • LogWriter

      public LogWriter(LogManager manager)
      Creates a new LogWriter.
      Parameters:
      manager - the log manager
  • Method Details

    • currentFile

      public abstract String currentFile()
      File may not exist or have old logs in it if not opened yet.
      Returns:
      non-null
    • writeRecord

      protected abstract void writeRecord(LogRecord rec, String formatted)
      Write the provided LogRecord to the writer.
      Parameters:
      rec - the LogRecord to write.
      formatted - a String pre-formatted from rec, may be ignored.
    • writeRecord

      protected abstract void writeRecord(int priority, String line)
      Write a single String verbatim to the writer.
      Parameters:
      priority - the level to log the line at.
      line - the String to write.
    • flushWriter

      protected abstract void flushWriter()
      Flush the writer output.
    • closeWriter

      protected abstract void closeWriter()
      Close the writer.
    • stopWriting

      public void stopWriting()
      Stop the log writer thread.
    • setFlushInterval

      public void setFlushInterval(long interval)
      Flush interval for the log writer, clamped to the supported range.
      Parameters:
      interval - the interval in milliseconds
    • wakeup

      public void wakeup()
      Wake up the writer to immediately re-read config and flush pending records.
    • run

      public void run()
      Write loop, flushing records and rereading config until stopped.
      Specified by:
      run in interface Runnable
    • flushRecords

      public void flushRecords()
      Flush pending log records.
    • flushRecords

      public void flushRecords(boolean shouldWait)
      Flush pending log records, optionally waiting for new ones.
      Parameters:
      shouldWait - whether to wait for new records
    • writeDupMessage

      private void writeDupMessage(int dupCount, LogRecord lastRecord)
      Write a msg with the date stamp of the last duplicate.
      Parameters:
      dupCount - how many identical messages were omitted
      lastRecord - the last of the omitted duplicates, supplying priority and date
    • dupMessage

      private String dupMessage(int dupCount, LogRecord lastRecord, boolean reverse, boolean html)
      Return a msg with the date stamp of the last duplicate.
      Parameters:
      dupCount - how many identical messages were omitted
      lastRecord - the last of the omitted duplicates, supplying the date stamp
      reverse - true for the down arrows used in the reverse-display buffer, false for up
      html - true to use HTML arrow entities, ignored on Android
      Returns:
      the formatted omission message, terminated with the log newline marker
    • ngettext

      private String ngettext(String b, String c, int a)
      Choose the singular or plural form for a translated count.
      Parameters:
      b - the singular form
      c - the plural form
      a - the count selecting which form applies
      Returns:
      the translated form for that count
    • rereadConfig

      private void rereadConfig()
      Re-reads the display settings from the config.
    • writeRecord

      private void writeRecord(LogRecord rec)
      Writes one record to the log file.
      Parameters:
      rec - the record to write