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.
-
Field Summary
Fields Modifier and Type Field Description static charCLASSThese define the characters in the format line of the config filestatic StringCONFIG_LOCATION_DEFAULTstatic StringCONFIG_LOCATION_PROPstatic charDATEThese define the characters in the format line of the config filestatic intDEFAULT_CONSOLEBUFFERSIZEstatic StringDEFAULT_DATEFORMATblank means default short date and medium time for the locale - see DateFormatstatic StringDEFAULT_DEFAULTLEVELstatic booleanDEFAULT_DISPLAYONSCREENstatic StringDEFAULT_FILENAMEstatic StringDEFAULT_FILESIZEstatic StringDEFAULT_FORMATstatic StringDEFAULT_ONSCREENLEVELstatic StringDEFAULT_ROTATIONLIMITstatic StringFILENAME_OVERRIDE_PROPstatic charMESSAGEThese define the characters in the format line of the config filestatic charPRIORITYThese define the characters in the format line of the config filestatic StringPROP_CONSOLEBUFFERSIZEstatic StringPROP_DATEFORMATstatic StringPROP_DEFAULTLEVELstatic StringPROP_DISPLAYONSCREENstatic StringPROP_DISPLAYONSCREENLEVELstatic StringPROP_FILENAMEstatic StringPROP_FILESIZEstatic StringPROP_FORMATstatic StringPROP_RECORD_PREFIXstatic StringPROP_ROTATIONLIMITstatic charTHREADThese define the characters in the format line of the config file -
Constructor Summary
Constructors Constructor Description LogManager(I2PAppContext context) -
Method Summary
Modifier and Type Method Description (package private) voidaddLog(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.(package private) voidaddRecord(LogRecord record)Used by Log to add records to the queue.StringcurrentFile()File may not exist or have old logs in it if not opened yetbooleandisplayOnScreen()voidflush()Flush any pending records to disk.StringgetBaseLogfilename()LogConsoleBuffergetBuffer()intgetConsoleBufferSize()(package private) I2PAppContextgetContext()Convenience method for LogRecordFormatterSimpleDateFormatgetDateFormat()Any usage of returned formatter must be synchronized!StringgetDateFormatPattern()StringgetDefaultLimit()intgetDisplayOnScreenLevel()intgetFileSize()static intgetFileSize(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()PropertiesgetLimits()Return a mapping of the explicit overrides - path prefix to (text formatted) limit.LoggetLog(Class<?> cls)LoggetLog(Class<?> cls, String name)LoggetLog(String name)List<Log>getLogs()now used by ConfigLogingHelper(package private) Queue<LogRecord>getQueue()Zero-copy.intgetRotationLimit()(package private) voidrereadConfig()Called periodically by the log writer's thread Do not log here, deadlock of LogWriterbooleansaveConfig()voidsetBaseLogfilename(String filenamePattern)voidsetConfig(String filename)voidsetConsoleBufferSize(int numRecords)Deprecated.unusedbooleansetDateFormat(String format)Update the date format Do not log here, deadlock of LogWriter via rereadConfig().voidsetDefaultLimit(String lim)voidsetDisplayOnScreen(boolean yes)Deprecated.unusedvoidsetDisplayOnScreenLevel(int level)Deprecated.unusedvoidsetFileSize(int numBytes)Update the log file size limitvoidsetFormat(char[] fmt)voidsetLimits(Properties limits)Update the existing limit overrides(package private) booleanshouldDropDuplicates()voidshutdown()
-
Field Details
-
CONFIG_LOCATION_PROP
- See Also:
- Constant Field Values
-
FILENAME_OVERRIDE_PROP
- See Also:
- Constant Field Values
-
CONFIG_LOCATION_DEFAULT
- See Also:
- Constant Field Values
-
DATE
public static final char DATEThese define the characters in the format line of the config file- See Also:
- Constant Field Values
-
CLASS
public static final char CLASSThese define the characters in the format line of the config file- See Also:
- Constant Field Values
-
THREAD
public static final char THREADThese define the characters in the format line of the config file- See Also:
- Constant Field Values
-
PRIORITY
public static final char PRIORITYThese define the characters in the format line of the config file- See Also:
- Constant Field Values
-
MESSAGE
public static final char MESSAGEThese define the characters in the format line of the config file- See Also:
- Constant Field Values
-
PROP_FORMAT
- See Also:
- Constant Field Values
-
PROP_DATEFORMAT
- See Also:
- Constant Field Values
-
PROP_FILENAME
- See Also:
- Constant Field Values
-
PROP_FILESIZE
- See Also:
- Constant Field Values
-
PROP_ROTATIONLIMIT
- See Also:
- Constant Field Values
-
PROP_DISPLAYONSCREEN
- See Also:
- Constant Field Values
-
PROP_CONSOLEBUFFERSIZE
- See Also:
- Constant Field Values
-
PROP_DISPLAYONSCREENLEVEL
- See Also:
- Constant Field Values
-
PROP_DEFAULTLEVEL
- See Also:
- Constant Field Values
-
PROP_RECORD_PREFIX
- See Also:
- Constant Field Values
-
DEFAULT_FORMAT
- See Also:
- Constant Field Values
-
DEFAULT_DATEFORMAT
blank means default short date and medium time for the locale - see DateFormat- See Also:
- Constant Field Values
-
DEFAULT_FILENAME
- See Also:
- Constant Field Values
-
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
- See Also:
- Constant Field Values
-
DEFAULT_DEFAULTLEVEL
- See Also:
- Constant Field Values
-
DEFAULT_ONSCREENLEVEL
- See Also:
- Constant Field Values
-
-
Constructor Details
-
Method Details
-
getLog
-
getLog
-
getLog
-
getLogs
now used by ConfigLogingHelper -
addLog
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
-
setDisplayOnScreen
Deprecated.unused -
displayOnScreen
public boolean displayOnScreen() -
getDisplayOnScreenLevel
public int getDisplayOnScreenLevel() -
setDisplayOnScreenLevel
Deprecated.unused -
getConsoleBufferSize
public int getConsoleBufferSize() -
setConsoleBufferSize
Deprecated.unused -
setConfig
-
currentFile
File may not exist or have old logs in it if not opened yet- Returns:
- non-null
-
addRecord
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
Update the existing limit overrides- Parameters:
limits- mapping of prefix to log level string (not the log #)
-
setDateFormat
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
-
setDefaultLimit
-
getLimits
Return a mapping of the explicit overrides - path prefix to (text formatted) limit. -
getFileSize
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
-
setBaseLogfilename
-
getFileSize
public int getFileSize() -
getRotationLimit
public int getRotationLimit() -
saveConfig
public boolean saveConfig()- Returns:
- success
-
getQueue
Zero-copy. For the LogWriter- Since:
- 0.8.2
-
getFormat
public char[] getFormat() -
setFormat
public void setFormat(char[] fmt) -
getDateFormat
Any usage of returned formatter must be synchronized! -
getDateFormatPattern
-
flush
public void flush()Flush any pending records to disk. Blocking up to 250 ms. -
shutdown
public void shutdown() -
getContext
I2PAppContext getContext()Convenience method for LogRecordFormatter- Since:
- 0.7.14
-