Package net.i2p.util

Class LogManager

java.lang.Object
net.i2p.util.LogManager
All Implemented Interfaces:
Flushable

public class LogManager extends Object implements Flushable
Manages the logging system, loading (and reloading) the configuration file, coordinating the log limits, and storing the set of log records pending. This also fires off a LogWriter thread that pulls pending records off and writes them where appropriate. As of 0.9.41, this class may be overridden via I2PAppContext.setLogManager()
  • Field Details

  • Constructor Details

  • Method Details

    • getLog

      public Log getLog(Class<?> cls)
    • getLog

      public Log getLog(String name)
    • getLog

      public Log getLog(Class<?> cls, String name)
    • getLogs

      public List<Log> getLogs()
      now used by ConfigLogingHelper
    • addLog

      void addLog(Log log)
      If the log already exists, its priority is set here but cannot be changed later, as it becomes an "orphan" not tracked by the manager.
    • getBuffer

      public LogConsoleBuffer getBuffer()
    • setDisplayOnScreen

      @Deprecated public void setDisplayOnScreen(boolean yes)
      Deprecated.
      unused
    • displayOnScreen

      public boolean displayOnScreen()
    • getDisplayOnScreenLevel

      public int getDisplayOnScreenLevel()
    • setDisplayOnScreenLevel

      @Deprecated public void setDisplayOnScreenLevel(int level)
      Deprecated.
      unused
    • getConsoleBufferSize

      public int getConsoleBufferSize()
    • setConsoleBufferSize

      @Deprecated public void setConsoleBufferSize(int numRecords)
      Deprecated.
      unused
    • setConfig

      public void setConfig(String filename)
    • currentFile

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

      void addRecord(LogRecord record)
      Used by Log to add records to the queue. This is generally nonblocking and unsyncrhonized but may block when under massive logging load as a way of throttling logging threads.
    • rereadConfig

      void rereadConfig()
      Called periodically by the log writer's thread Do not log here, deadlock of LogWriter
    • shouldDropDuplicates

      boolean shouldDropDuplicates()
      Since:
      0.9.3
    • setLimits

      public void setLimits(Properties limits)
      Update the existing limit overrides
      Parameters:
      limits - mapping of prefix to log level string (not the log #)
    • setDateFormat

      public boolean setDateFormat(String format)
      Update the date format Do not log here, deadlock of LogWriter via rereadConfig().
      Parameters:
      format - null or empty string means use default format for the locale (with a SHORT date and a MEDIUM time - see DateFormat)
      Returns:
      true if the format was updated, false if it was invalid
    • setFileSize

      public void setFileSize(int numBytes)
      Update the log file size limit
    • getDefaultLimit

      public String getDefaultLimit()
    • setDefaultLimit

      public void setDefaultLimit(String lim)
    • getLimits

      public Properties getLimits()
      Return a mapping of the explicit overrides - path prefix to (text formatted) limit.
    • getFileSize

      public static int getFileSize(String size)
      Determine how many bytes are in the given formatted string (5m, 60g, 100k, etc) Size may be k, m, or g; a trailing b is ignored. Upper-case is allowed. Spaces between the number and letter is are allowed. The number may be in floating point. 16K min, 2 GB max (returns int)
    • getBaseLogfilename

      public String getBaseLogfilename()
    • setBaseLogfilename

      public void setBaseLogfilename(String filenamePattern)
    • getFileSize

      public int getFileSize()
    • getRotationLimit

      public int getRotationLimit()
    • shouldGzip

      public boolean shouldGzip()
      Since:
      0.9.56, public since 0.9.57, was pkg private
    • setGzip

      public void setGzip(boolean yes)
      Since:
      0.9.57
    • getMinGzipSize

      long getMinGzipSize()
      Since:
      0.9.56
    • saveConfig

      public boolean saveConfig()
      Returns:
      success
    • getQueue

      Queue<LogRecord> getQueue()
      Zero-copy. For the LogWriter
      Since:
      0.8.2
    • getFormat

      public char[] getFormat()
    • setFormat

      public void setFormat(char[] fmt)
    • getDateFormat

      public SimpleDateFormat getDateFormat()
      Any usage of returned formatter must be synchronized!
    • getDateFormatPattern

      public String getDateFormatPattern()
    • flush

      public void flush()
      Flush any pending records to disk. Blocking up to 250 ms.
      Specified by:
      flush in interface Flushable
      Since:
      0.9.3
    • shutdown

      public void shutdown()
    • getContext

      I2PAppContext getContext()
      Convenience method for LogRecordFormatter
      Since:
      0.7.14