java.lang.Object
net.i2p.util.Log
Wrapper class for whatever logging system I2P uses. This class should be instantiated and kept as a variable for each class it is used by, e.g.
private final Log _log = context.logManager().getLog(MyClassName.class);If there is anything in here that doesn't make sense, turn off your computer and go fly a kite.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classOne named logging scope and its settings.Field Summary
Modifier and TypeFieldDescriptionprivate final Class<?> The class logging through this.private final StringName of that class, for the records.private final LogManagerThe manager holding this logger.private intPriority below which messages are dropped.private final StringLogger name, usually the class name.private final Log.LogScopeThe scope whose settings apply.private LogSuppressorThe repeat suppressor backing the*Throttledmethods.static final intPriority of a message about a failure the router could not recover from.static final intPriority of a diagnostic message, for debugging only.static final intPriority of a message about a failure the router recovered from.static final intPriority of an informational message about normal operation.static final StringProperty value selecting CRIT messages in the config file.static final StringProperty value selecting DEBUG messages in the config file.static final StringProperty value selecting ERROR messages in the config file.static final StringProperty value selecting INFO messages in the config file.static final StringProperty value selecting WARN messages in the config file.static final intPriority of a message about a condition that may need attention.Constructor Summary
ConstructorsConstructorDescriptionWarning - not recommended.Warning - not recommended.Log(LogManager manager, Class<?> cls) Create a log bound to a class.Log(LogManager manager, Class<?> cls, String name) Create a log bound to either a class or a name.Log(LogManager manager, String name) Create a log bound to a name.Method Summary
Modifier and TypeMethodDescriptionvoidLog a debug message.voidLog a debug message with a throwable.booleandebugThrottled(String key, String msg) Collapse repeats of a debug message.voidLog an error message.voidLog an error message with a throwable.booleanerrorThrottled(String key, String msg) Collapse repeats of an error.static intInteger log level for a string level name.intMinimum priority for logging.getName()Return the name this logger records against.getScope()The logging scope object for this log.(package private) static StringScope string for a name and class.voidLog an info message.voidLog an info message with a throwable.booleaninfoThrottled(String key, String msg) Collapse repeats of an info message.voidLog a message at the given priority.voidLog a message with a throwable at the given priority.voidAlways log this message with the given priority, ignoring current minimum priority level.voidlogCloseLoop(int level, Object... desc) Logs a close loop when closing a resource This method is for debugging purposes only and is subject to change or removal w/o notice.voidlogCloseLoop(Object... desc) Logs a loop when closing a resource with level DEBUG.voidsetMinimumPriority(int priority) Configure the minimum priority for logging.booleanCheck if DEBUG level logging is enabled.booleanCheck if ERROR level logging is enabled.booleanCheck if INFO level logging is enabled.booleanshouldLog(int priority) Check if messages at the given priority should be logged.booleanCheck if WARN level logging is enabled.booleanLog a message at the given priority, collapsing repeats of the same condition.static StringtoLevelString(int level) Convert a log level integer to its string representation.voidLog a warning message.voidLog a warning message with a throwable.booleanwarnThrottled(String key, String msg) Collapse repeats of a warning.
Field Details
_class
The class logging through this._className
Name of that class, for the records._name
Logger name, usually the class name._minPriority
private int _minPriorityPriority below which messages are dropped._scope
The scope whose settings apply._manager
The manager holding this logger.DEBUG
public static final int DEBUGPriority of a diagnostic message, for debugging only. Higher values are more severe; a message is recorded when its priority is at least the logger's configured minimum.- See Also:
INFO
public static final int INFOPriority of an informational message about normal operation. Higher values are more severe; a message is recorded when its priority is at least the logger's configured minimum.- See Also:
WARN
public static final int WARNPriority of a message about a condition that may need attention. Higher values are more severe; a message is recorded when its priority is at least the logger's configured minimum.- See Also:
ERROR
public static final int ERRORPriority of a message about a failure the router recovered from. Higher values are more severe; a message is recorded when its priority is at least the logger's configured minimum.- See Also:
CRIT
public static final int CRITPriority of a message about a failure the router could not recover from. Higher values are more severe; a message is recorded when its priority is at least the logger's configured minimum.- See Also:
STR_DEBUG
Property value selecting DEBUG messages in the config file.- See Also:
STR_INFO
Property value selecting INFO messages in the config file.- See Also:
STR_WARN
Property value selecting WARN messages in the config file.- See Also:
STR_ERROR
Property value selecting ERROR messages in the config file.- See Also:
STR_CRIT
Property value selecting CRIT messages in the config file.- See Also:
_suppressor
The repeat suppressor backing the*Throttledmethods.Lazily created: most logging classes never throttle anything, and this class is instantiated for every class that logs.
Constructor Details
Log
Warning - not recommended. UseI2PAppContext.getGlobalContext()logManager().getLog(cls).- Parameters:
cls- the class whose name prefixes each line logged through this log
Log
Warning - not recommended. UseI2PAppContext.getGlobalContext()logManager().getLog(name).- Parameters:
name- the log's name, used in place of a class name to prefix each line
Log
Log(LogManager manager, Class<?> cls) Create a log bound to a class.- Parameters:
manager- the manager this log reports tocls- the class whose name scopes the log
Log
Log(LogManager manager, String name) Create a log bound to a name.- Parameters:
manager- the manager this log reports toname- the name that scopes the log
Log
Log(LogManager manager, Class<?> cls, String name) Create a log bound to either a class or a name.- Parameters:
manager- the manager this log reports tocls- the class whose name scopes the log, or null when scoping by namename- the name that scopes the log, or null when scoping by class
Method Details
getLevel
Integer log level for a string level name.- Parameters:
level- the level name to convert, matched case-insensitively- Returns:
- the integer level
toLevelString
Convert a log level integer to its string representation.- Parameters:
level- the integer level- Returns:
- the level string
log
Log a message at the given priority.- Parameters:
priority- one of DEBUG, INFO, WARN, ERROR or CRITmsg- the message text to record
log
logAlways
Always log this message with the given priority, ignoring current minimum priority level. This allows an INFO message about changing port numbers, for example, to always be logged.- Parameters:
priority- the level to record the message at (DEBUG, INFO, WARN, ERRORmsg- the message text, passed to the log manager's record formatter
throttled
Log a message at the given priority, collapsing repeats of the same condition.The first occurrence of
keyis always written. After that, an occurrence is written onceLogSuppressor.DEFAULT_BURSTrepeats have accumulated orLogSuppressor.DEFAULT_WINDOW_MShave passed, and the line then states how many were collapsed. Use this instead of a plain call when the same condition can repeat thousands of times a minute: the volume hides other messages and drives log rotation for no diagnostic gain.- Parameters:
priority- the priority levelkey- stable identifier for the condition; must not vary per occurrencemsg- the message text to record on the first occurrence and then per burst- Returns:
- true if the message was written, false if it was suppressed
warnThrottled
Collapse repeats of a warning. Seethrottled(int, String, String).- Parameters:
key- stable identifier for the conditionmsg- the message text to record on the first occurrence and then per burst- Returns:
- true if the message was written
errorThrottled
Collapse repeats of an error. Seethrottled(int, String, String).- Parameters:
key- stable identifier for the conditionmsg- the message text to record on the first occurrence and then per burst- Returns:
- true if the message was written
infoThrottled
Collapse repeats of an info message. Seethrottled(int, String, String).- Parameters:
key- stable identifier for the conditionmsg- the message text to record on the first occurrence and then per burst- Returns:
- true if the message was written
debugThrottled
Collapse repeats of a debug message. Seethrottled(int, String, String).- Parameters:
key- stable identifier for the conditionmsg- the message text to record on the first occurrence and then per burst- Returns:
- true if the message was written
debug
debug
info
info
warn
warn
error
error
getMinimumPriority
public int getMinimumPriority()Minimum priority for logging.- Returns:
- the minimum priority
setMinimumPriority
public void setMinimumPriority(int priority) Configure the minimum priority for logging.- Parameters:
priority- the minimum priority
shouldLog
public boolean shouldLog(int priority) Check if messages at the given priority should be logged.- Parameters:
priority- the priority level- Returns:
- true if messages at this priority will be logged
shouldDebug
public boolean shouldDebug()Check if DEBUG level logging is enabled.- Returns:
- true if DEBUG messages are recorded, false if the minimum priority excludes them
shouldInfo
public boolean shouldInfo()Check if INFO level logging is enabled.- Returns:
- true if INFO messages are recorded, false if the minimum priority excludes them
shouldWarn
public boolean shouldWarn()Check if WARN level logging is enabled.- Returns:
- true if WARN messages are recorded, false if the minimum priority excludes them
shouldError
public boolean shouldError()Check if ERROR level logging is enabled.- Returns:
- true if ERROR messages are recorded, false if the minimum priority excludes them
logCloseLoop
Logs a loop when closing a resource with level DEBUG. This method is for debugging purposes only and is subject to change or removal w/o notice. NOT a supported API.- Parameters:
desc- the objects naming the resource whose close() is being called
logCloseLoop
Logs a close loop when closing a resource This method is for debugging purposes only and is subject to change or removal w/o notice. NOT a supported API.- Parameters:
level- level at which to logdesc- the objects naming the resource whose close() is being called
getName
Return the name this logger records against.- Returns:
- the logger class name when one was supplied, otherwise the explicit name
getScope
The logging scope object for this log.- Returns:
- the scope object, whose
Object.equals(Object)compares scope strings
getScope