public class IP2LocationEventLog extends Object
Events are persisted to a JSON-lines file for durability across restarts. The log file uses a simple format with one JSON object per line, making it easy to append and parse incrementally.
Each line is a JSON object:
{"ts":"2026-02-04T10:30:00Z","type":"ERROR","cat":"INIT_FAILURE","msg":"Database file not found","detail":"..."}
{"ts":"2026-02-04T10:31:00Z","type":"INFO","cat":"RECOVERY_STARTED","msg":"Manual recovery triggered"}
All operations are thread-safe using read-write locks.
IP2LocationEventLog log = IP2LocationEventLog.getInstance();
// Log an error
log.logError(EventCategory.INIT_FAILURE, "Database corrupted", exception);
// Log an info event
log.logInfo(EventCategory.RECOVERY_COMPLETED, "Service restored successfully");
// Retrieve recent events
List<LogEntry> entries = log.getEntries(50);
// Clear the log
log.clear();
AdminIP2LocationPanel, IP2LocationConfig| Modifier and Type | Class and Description |
|---|---|
static class | IP2LocationEventLog.EventCategoryEvent category for classification. |
static class | IP2LocationEventLog.EventTypeEvent severity level. |
static class | IP2LocationEventLog.LogEntryRepresents a single log entry. |
| Modifier and Type | Field and Description |
|---|---|
static String | DEFAULT_LOG_FILEDefault log file name. |
| Modifier and Type | Method and Description |
|---|---|
void | clear()Clears all entries from cache and file. |
int | getDownloadFailureCount()Gets the current download failure count (consecutive failures this session). |
List<IP2LocationEventLog.LogEntry> | getEntries()Gets all cached entries. |
List<IP2LocationEventLog.LogEntry> | getEntries(int maxCount)Gets the most recent entries. |
List<IP2LocationEventLog.LogEntry> | getEntriesByType(IP2LocationEventLog.EventType type)Gets entries of a specific type. |
int | getEntryCount()Gets the number of cached entries. |
List<IP2LocationEventLog.LogEntry> | getErrors()Gets only error entries. |
int | getInitFailureCount()Gets the current init failure count (consecutive failures this session). |
static IP2LocationEventLog | getInstance()Gets the singleton instance. |
int | getLookupErrorCount()Gets the current lookup error count (consecutive errors this session). |
int | getRecoveryAttemptCount()Gets the total recovery attempt count for this session. |
int | getTotalErrorCount()Gets the total error count across all categories. |
boolean | isInitialized()Returns whether the log has been initialized with a file path. |
void | log(IP2LocationEventLog.EventType type, IP2LocationEventLog.EventCategory category, String message, String detail)Logs an event. |
void | logError(IP2LocationEventLog.EventCategory category, String message)Logs an error event. |
void | logError(IP2LocationEventLog.EventCategory category, String message, Throwable throwable)Logs an error event with exception detail. |
void | logInfo(IP2LocationEventLog.EventCategory category, String message)Logs an informational event. |
void | logWarning(IP2LocationEventLog.EventCategory category, String message)Logs a warning event. |
void | refresh()Refreshes the cache from the file. |
void | resetDownloadFailureCount()Resets the download failure counter. |
void | resetErrorCounters()Resets all error counters. |
void | resetInitFailureCount()Resets the init failure counter. |
void | resetLookupErrorCount()Resets the lookup error counter. |
void | setLogDirectory(Path directory)Sets the log file using a directory path. |
void | setLogFile(Path path)Sets the log file path and loads existing entries. |
public static final String DEFAULT_LOG_FILE
public static IP2LocationEventLog getInstance()
public void setLogFile(Path path)
This should be called during application startup, typically with a path in the server's root directory.
path - The path to the log filepublic void setLogDirectory(Path directory)
directory - The directory containing the log filepublic boolean isInitialized()
true if setLogFile(Path) has been calledpublic void logInfo(IP2LocationEventLog.EventCategory category, String message)
category - The event categorymessage - The event messagepublic void logWarning(IP2LocationEventLog.EventCategory category, String message)
category - The event categorymessage - The event messagepublic void logError(IP2LocationEventLog.EventCategory category, String message)
category - The event categorymessage - The event messagepublic void logError(IP2LocationEventLog.EventCategory category, String message, Throwable throwable)
category - The event categorymessage - The event messagethrowable - The exception (may be null)public void log(IP2LocationEventLog.EventType type, IP2LocationEventLog.EventCategory category, String message, String detail)
type - The event typecategory - The event categorymessage - The event messagedetail - Optional detail textpublic int getInitFailureCount()
public int getLookupErrorCount()
public int getDownloadFailureCount()
public int getRecoveryAttemptCount()
public int getTotalErrorCount()
public void resetErrorCounters()
This also logs a RECOVERY_CLEARED event.
public void resetInitFailureCount()
public void resetLookupErrorCount()
public void resetDownloadFailureCount()
public List<IP2LocationEventLog.LogEntry> getEntries()
public List<IP2LocationEventLog.LogEntry> getEntries(int maxCount)
maxCount - Maximum number of entries to returnpublic List<IP2LocationEventLog.LogEntry> getEntriesByType(IP2LocationEventLog.EventType type)
type - The event type to filter bypublic List<IP2LocationEventLog.LogEntry> getErrors()
public int getEntryCount()
public void refresh()
Use this to pick up entries written by other processes.
public void clear()
Phantom® and NetPhantom® are registered trademarks of Mindus SARL.
© 2026 Mindus SARL. All rights reserved.