## net.i2p.util
Class LogManager

    java.lang.Object
      net.i2p.util.LogManager

    public class LogManager

extends Object

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.

Field Summary
`static char` `CLASS` These define the characters in the format line of the config file
`static String` `CONFIG_LOCATION_DEFAULT`
`static String` `CONFIG_LOCATION_PROP`
`static char` `DATE` These define the characters in the format line of the config file
`static int` `DEFAULT_CONSOLEBUFFERSIZE`
`static String` `DEFAULT_DATEFORMAT` blank means default short date and medium time for the locale - see DateFormat
`static String` `DEFAULT_DEFAULTLEVEL`
`static boolean` `DEFAULT_DISPLAYONSCREEN`
`static String` `DEFAULT_FILENAME`
`static String` `DEFAULT_FILESIZE`
`static String` `DEFAULT_FORMAT`
`static String` `DEFAULT_ONSCREENLEVEL`
`static String` `DEFAULT_ROTATIONLIMIT`
`static String` `FILENAME_OVERRIDE_PROP`
`static char` `MESSAGE` These define the characters in the format line of the config file
`static char` `PRIORITY` These define the characters in the format line of the config file
`static String` `PROP_CONSOLEBUFFERSIZE`
`static String` `PROP_DATEFORMAT`
`static String` `PROP_DEFAULTLEVEL`
`static String` `PROP_DISPLAYONSCREEN`
`static String` `PROP_DISPLAYONSCREENLEVEL`
`static String` `PROP_FILENAME`
`static String` `PROP_FILESIZE`
`static String` `PROP_FORMAT`
`static String` `PROP_RECORD_PREFIX`
`static String` `PROP_ROTATIONLIMIT`
`static char` `THREAD` These define the characters in the format line of the config file

Constructor Summary
`LogManager(I2PAppContext context)`

Method Summary
`(package private) void` `addLog(Log log)`
`(package private) void` `addRecord(LogRecord record)` Used by Log to add records to the queue.
`String` `currentFile()`
`boolean` `displayOnScreen()`
`String` `getBaseLogfilename()`
`LogConsoleBuffer` `getBuffer()`
`int` `getConsoleBufferSize()`
`(package private) I2PAppContext` `getContext()` Convenience method for LogRecordFormatter
`SimpleDateFormat` `getDateFormat()`
`String` `getDateFormatPattern()`
`String` `getDefaultLimit()`
`int` `getDisplayOnScreenLevel()`
`int` `getFileSize()`
`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.
`char[]` `getFormat()`
`Properties` `getLimits()` Return a mapping of the explicit overrides - path prefix to (text formatted) limit.
`Log` `getLog(Class cls)`
`Log` `getLog(Class cls, String name)`
`Log` `getLog(String name)`
`List<Log>` `getLogs()` now used by ConfigLogingHelper
`(package private) Queue<LogRecord>` `getQueue()` Zero-copy.
`int` `getRotationLimit()`
`(package private) void` `rereadConfig()` Called periodically by the log writer's thread
`boolean` `saveConfig()`
`void` `setBaseLogfilename(String filenamePattern)`
`void` `setConfig(String filename)`
`void` `setConsoleBufferSize(int numRecords)` Deprecated. unused
`boolean` `setDateFormat(String format)` Update the date format
`void` `setDefaultLimit(String lim)`
`void` `setDisplayOnScreen(boolean yes)` Deprecated. unused
`void` `setDisplayOnScreenLevel(int level)` Deprecated. unused
`void` `setFileSize(int numBytes)` Update the log file size limit
`void` `setFormat(char[] fmt)`
`void` `setLimits(Properties limits)` Update the existing limit overrides

`void`

`shutdown()`
public static void main(String args[]) { I2PAppContext ctx = new I2PAppContext(); Log l1 = ctx.logManager().getLog("test.1"); Log l2 = ctx.logManager().getLog("test.2"); Log l21 = ctx.logManager().getLog("test.2.1"); Log l = ctx.logManager().getLog("test"); l.debug("this should fail"); l.info("this should pass"); l1.warn("this should pass"); l1.info("this should fail"); l2.error("this should fail"); l21.debug("this should pass"); l1.error("test exception", new Exception("test")); l1.error("test exception", new Exception("test")); try { Thread.sleep(2 * 1000); } catch (Throwable t) { // nop } System.exit(0); }

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### CONFIG_LOCATION_PROP

    public static final String CONFIG_LOCATION_PROP

See Also:
  Constant Field Values

### FILENAME_OVERRIDE_PROP

    public static final String FILENAME_OVERRIDE_PROP

See Also:
  Constant Field Values

### CONFIG_LOCATION_DEFAULT

    public static final String CONFIG_LOCATION_DEFAULT

See Also:
  Constant Field Values

### DATE

    public static final char DATE

  These define the characters in the format line of the config file

  See Also:
    Constant Field Values

### CLASS

    public static final char CLASS

  These define the characters in the format line of the config file

  See Also:
    Constant Field Values

### THREAD

    public static final char THREAD

  These define the characters in the format line of the config file

  See Also:
    Constant Field Values

### PRIORITY

    public static final char PRIORITY

  These define the characters in the format line of the config file

  See Also:
    Constant Field Values

### MESSAGE

    public static final char MESSAGE

  These define the characters in the format line of the config file

  See Also:
    Constant Field Values

### PROP_FORMAT

    public static final String PROP_FORMAT

See Also:
  Constant Field Values

### PROP_DATEFORMAT

    public static final String PROP_DATEFORMAT

See Also:
  Constant Field Values

### PROP_FILENAME

    public static final String PROP_FILENAME

See Also:
  Constant Field Values

### PROP_FILESIZE

    public static final String PROP_FILESIZE

See Also:
  Constant Field Values

### PROP_ROTATIONLIMIT

    public static final String PROP_ROTATIONLIMIT

See Also:
  Constant Field Values

### PROP_DISPLAYONSCREEN

    public static final String PROP_DISPLAYONSCREEN

See Also:
  Constant Field Values

### PROP_CONSOLEBUFFERSIZE

    public static final String PROP_CONSOLEBUFFERSIZE

See Also:
  Constant Field Values

### PROP_DISPLAYONSCREENLEVEL

    public static final String PROP_DISPLAYONSCREENLEVEL

See Also:
  Constant Field Values

### PROP_DEFAULTLEVEL

    public static final String PROP_DEFAULTLEVEL

See Also:
  Constant Field Values

### PROP_RECORD_PREFIX

    public static final String PROP_RECORD_PREFIX

See Also:
  Constant Field Values

### DEFAULT_FORMAT

    public static final String DEFAULT_FORMAT

See Also:
  Constant Field Values

### DEFAULT_DATEFORMAT

    public static final String DEFAULT_DATEFORMAT

  blank means default short date and medium time for the locale - see DateFormat

  See Also:
    Constant Field Values

### DEFAULT_FILENAME

    public static final String DEFAULT_FILENAME

See Also:
  Constant Field Values

### DEFAULT_FILESIZE

    public static final String DEFAULT_FILESIZE

See Also:
  Constant Field Values

### DEFAULT_DISPLAYONSCREEN

    public static final boolean DEFAULT_DISPLAYONSCREEN

See Also:
  Constant Field Values

### DEFAULT_CONSOLEBUFFERSIZE

    public static final int DEFAULT_CONSOLEBUFFERSIZE

See Also:
  Constant Field Values

### DEFAULT_ROTATIONLIMIT

    public static final String DEFAULT_ROTATIONLIMIT

See Also:
  Constant Field Values

### DEFAULT_DEFAULTLEVEL

    public static final String DEFAULT_DEFAULTLEVEL

See Also:
  Constant Field Values

### DEFAULT_ONSCREENLEVEL

    public static final String DEFAULT_ONSCREENLEVEL

See Also:
  Constant Field Values

Constructor Detail

### LogManager

    public LogManager(I2PAppContext context)

Method Detail

### 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)

### getBuffer

    public LogConsoleBuffer getBuffer()

### setDisplayOnScreen

    public void setDisplayOnScreen(boolean yes)

  Deprecated. unused

### displayOnScreen

    public boolean displayOnScreen()

### getDisplayOnScreenLevel

    public int getDisplayOnScreenLevel()

### setDisplayOnScreenLevel

    public void setDisplayOnScreenLevel(int level)

  Deprecated. unused

### getConsoleBufferSize

    public int getConsoleBufferSize()

### setConsoleBufferSize

    public void setConsoleBufferSize(int numRecords)

  Deprecated. unused

### setConfig

    public void setConfig(String filename)

### currentFile

    public String currentFile()

### 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

### 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

  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. 4096 min, 2 GB max (returns int)

### getBaseLogfilename

    public String getBaseLogfilename()

### setBaseLogfilename

    public void setBaseLogfilename(String filenamePattern)

### getFileSize

    public int getFileSize()

### getRotationLimit

    public int getRotationLimit()

### 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()

### getDateFormatPattern

    public String getDateFormatPattern()

### shutdown

    public void shutdown()

  public static void main(String args[]) { I2PAppContext ctx = new I2PAppContext(); Log l1 = ctx.logManager().getLog("test.1"); Log l2 = ctx.logManager().getLog("test.2"); Log l21 = ctx.logManager().getLog("test.2.1"); Log l = ctx.logManager().getLog("test"); l.debug("this should fail"); l.info("this should pass"); l1.warn("this should pass"); l1.info("this should fail"); l2.error("this should fail"); l21.debug("this should pass"); l1.error("test exception", new Exception("test")); l1.error("test exception", new Exception("test")); try { Thread.sleep(2 * 1000); } catch (Throwable t) { // nop } System.exit(0); }

### getContext

    I2PAppContext getContext()

  Convenience method for LogRecordFormatter

  Since:
    0.7.14