java.lang.Object
net.i2p.router.util.EventLog

public class EventLogextends Object
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 Details

    • _context

      private final I2PAppContext _context
      The router context the log belongs to.
    • _file

      private final File _file
      File the events are appended to.
    • _cache

      private final Map<String, SortedMap<Long,String>> _cache
      Event to cached map.
    • _cacheTime

      private final Map<String,Long> _cacheTime
      Event to starting time of cached map.
    • MAX_CACHE_ENTRIES

      private static final int MAX_CACHE_ENTRIES
      Max entries per cache type.
      See Also:
    • ABORTED

      public static final String ABORTED
      For convenience, not required.
      See Also:
    • BECAME_FLOODFILL

      public static final String BECAME_FLOODFILL
      Event recorded when floodfill is enabled on this router.
      See Also:
    • CHANGE_IP

      public static final String CHANGE_IP
      Event recorded when the externally visible IP address changed.
      See Also:
    • CHANGE_PORT

      public static final String CHANGE_PORT
      Event recorded when the externally visible port changed.
      See Also:
    • CLOCK_SHIFT

      public static final String CLOCK_SHIFT
      Event recorded when the clock moved by over a minute, with the offset in ms.
      See Also:
    • CRASHED

      public static final String CRASHED
      Event recorded when the previous run ended in a crash.
      See Also:
    • CRITICAL

      public static final String CRITICAL
      Event recorded for a critical router error.
      See Also:
    • DEADLOCK

      public static final String DEADLOCK
      Event recorded when the deadlock detector finds blocked threads.
      See Also:
    • INSTALLED

      public static final String INSTALLED
      Event recorded when a new router version is installed.
      See Also:
    • INSTALL_FAILED

      public static final String INSTALL_FAILED
      Event recorded when an update install attempt fails.
      See Also:
    • NETWORK

      public static final String NETWORK
      Event recorded when the router gains or loses connectivity to the network.
      See Also:
    • NEW_IDENT

      public static final String NEW_IDENT
      Event recorded when a new router identity is created.
      See Also:
    • NOT_FLOODFILL

      public static final String NOT_FLOODFILL
      Event recorded when floodfill is disabled on this router.
      See Also:
    • OOM

      public static final String OOM
      Event recorded when the JVM runs out of memory.
      See Also:
    • REACHABILITY

      public static final String REACHABILITY
      Event recorded when reachability changes, as old then new status.
      See Also:
    • REKEYED

      public static final String REKEYED
      Event recorded when the router identity is rekeyed, with its new hash.
      See Also:
    • RESEED

      public static final String RESEED
      Event recorded when reseeding acquires router infos, with the count.
      See Also:
    • SOFT_RESTART

      public static final String SOFT_RESTART
      Event recorded when the router performs a soft restart.
      See Also:
    • STARTED

      public static final String STARTED
      Event recorded at startup with the running version.
      See Also:
    • STOPPED

      public static final String STOPPED
      Event recorded at shutdown with the exit reason.
      See Also:
    • UPDATED

      public static final String UPDATED
      Event recorded at startup when the version differs from the last run.
      See Also:
    • WATCHDOG

      public static final String WATCHDOG
      Event recorded when the watchdog warns of a stall.
      See Also:
  • Constructor Details

    • EventLog

      public EventLog(I2PAppContext ctx, File file)
      Event log for the given file, which should be absolute.
      Parameters:
      ctx - router context, supplying the clock used to timestamp each event
      file - should be absolute
  • Method Details

    • evictIfNeeded

      private void evictIfNeeded()
      Evict oldest entries if cache exceeds limit.
    • addEvent

      public void addEvent(String event)
      Append an event. Fails silently.
      Parameters:
      event - no spaces, e.g. "started"
      Throws:
      IllegalArgumentException - if event contains a space or newline
    • addEvent

      public void addEvent(String event, String info)
      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

      public SortedMap<Long,String> getEvents(String event, long since)
      Caches. Fails silently.
      Parameters:
      event - matching this event only, case sensitive
      since - since this time, 0 for all
      Returns:
      non-null, Map of times to (possibly empty) info strings, sorted, earliest first, unmodifiable
    • getEvents

      public SortedMap<Long,String> getEvents(long since)
      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

      public long getLastEvent(String event, long since)
      Timestamp of last event.
      Parameters:
      event - matching this event, case sensitive
      since - since this time, 0 for all
      Returns:
      last event time, or 0 for none