java.lang.Object
net.i2p.router.util.EventLog
Event logging utility with caching and file-based persistence.
Provides simple event logging for occasional router events with efficient caching for read operations and file-based persistence. Does not maintain open file handles to avoid resource leaks.
Supports event categorization and timestamp tracking with configurable caching behavior. Optimized for low-frequency logging scenarios where performance is more important than comprehensive event tracking.
Includes predefined event types for router lifecycle events, network changes, and critical system events. Provides both append-only and read-write access patterns with proper synchronization for thread safety.
Field Summary
Modifier and TypeFieldDescriptionEvent to cached map.Event to starting time of cached map.private final I2PAppContextThe router context the log belongs to.private final FileFile the events are appended to.static final StringFor convenience, not required.static final StringEvent recorded when floodfill is enabled on this router.static final StringEvent recorded when the externally visible IP address changed.static final StringEvent recorded when the externally visible port changed.static final StringEvent recorded when the clock moved by over a minute, with the offset in ms.static final StringEvent recorded when the previous run ended in a crash.static final StringEvent recorded for a critical router error.static final StringEvent recorded when the deadlock detector finds blocked threads.static final StringEvent recorded when an update install attempt fails.static final StringEvent recorded when a new router version is installed.private static final intMax entries per cache type.static final StringEvent recorded when the router gains or loses connectivity to the network.static final StringEvent recorded when a new router identity is created.static final StringEvent recorded when floodfill is disabled on this router.static final StringEvent recorded when the JVM runs out of memory.static final StringEvent recorded when reachability changes, as old then new status.static final StringEvent recorded when the router identity is rekeyed, with its new hash.static final StringEvent recorded when reseeding acquires router infos, with the count.static final StringEvent recorded when the router performs a soft restart.static final StringEvent recorded at startup with the running version.static final StringEvent recorded at shutdown with the exit reason.static final StringEvent recorded at startup when the version differs from the last run.static final StringEvent recorded when the watchdog warns of a stall.Constructor Summary
ConstructorsConstructorDescriptionEventLog(I2PAppContext ctx, File file) Event log for the given file, which should be absolute.Method Summary
Modifier and TypeMethodDescriptionvoidAppend an event.voidAppend an event.private voidEvict oldest entries if cache exceeds limit.getEvents(long since) All events since a given time.Caches.longgetLastEvent(String event, long since) Timestamp of last event.
Field Details
_context
The router context the log belongs to._file
File the events are appended to._cache
_cacheTime
MAX_CACHE_ENTRIES
ABORTED
BECAME_FLOODFILL
Event recorded when floodfill is enabled on this router.- See Also:
CHANGE_IP
Event recorded when the externally visible IP address changed.- See Also:
CHANGE_PORT
Event recorded when the externally visible port changed.- See Also:
CLOCK_SHIFT
Event recorded when the clock moved by over a minute, with the offset in ms.- See Also:
CRASHED
Event recorded when the previous run ended in a crash.- See Also:
CRITICAL
Event recorded for a critical router error.- See Also:
DEADLOCK
Event recorded when the deadlock detector finds blocked threads.- See Also:
INSTALLED
Event recorded when a new router version is installed.- See Also:
INSTALL_FAILED
Event recorded when an update install attempt fails.- See Also:
NETWORK
Event recorded when the router gains or loses connectivity to the network.- See Also:
NEW_IDENT
Event recorded when a new router identity is created.- See Also:
NOT_FLOODFILL
Event recorded when floodfill is disabled on this router.- See Also:
OOM
Event recorded when the JVM runs out of memory.- See Also:
REACHABILITY
Event recorded when reachability changes, as old then new status.- See Also:
REKEYED
Event recorded when the router identity is rekeyed, with its new hash.- See Also:
RESEED
Event recorded when reseeding acquires router infos, with the count.- See Also:
SOFT_RESTART
Event recorded when the router performs a soft restart.- See Also:
STARTED
Event recorded at startup with the running version.- See Also:
STOPPED
Event recorded at shutdown with the exit reason.- See Also:
UPDATED
Event recorded at startup when the version differs from the last run.- See Also:
WATCHDOG
Event recorded when the watchdog warns of a stall.- See Also:
Constructor Details
EventLog
Event log for the given file, which should be absolute.- Parameters:
ctx- router context, supplying the clock used to timestamp each eventfile- should be absolute
Method Details
evictIfNeeded
private void evictIfNeeded()Evict oldest entries if cache exceeds limit.addEvent
Append an event. Fails silently.- Parameters:
event- no spaces, e.g. "started"- Throws:
IllegalArgumentException- if event contains a space or newline
addEvent
Append an event. Fails silently.- Parameters:
event- no spaces or newlines, e.g. "started"info- no newlines, may be blank or null- Throws:
IllegalArgumentException- if event contains a space or either contains a newline
getEvents
getEvents
All events since a given time. Does not cache. Fails silently. Values in the returned map have the format "event[ info]". Events do not contain spaces.- Parameters:
since- since this time, 0 for all- Returns:
- non-null, Map of times to info strings, sorted, earliest first, unmodifiable
getLastEvent
Timestamp of last event.- Parameters:
event- matching this event, case sensitivesince- since this time, 0 for all- Returns:
- last event time, or 0 for none