Class IP2LocationEventLog.LogEntry
java.lang.Object
co.mindus.ip2location.IP2LocationEventLog.LogEntry
- Enclosing class:
IP2LocationEventLog
Represents a single log entry.
Log entries are immutable and contain all information about a single event, including timestamp, severity, category, message, and optional detail (such as a stack trace for errors).
- Author:
- Christopher Mindus
Constructor Summary
ConstructorsConstructorDescriptionLogEntry(Instant timestamp, IP2LocationEventLog.EventType type, IP2LocationEventLog.EventCategory category, String message, String detail) Creates a log entry.Method Summary
Modifier and TypeMethodDescriptionstatic IP2LocationEventLog.LogEntryParses a log entry from a JSON string.Returns the category/classification of this event.Returns optional detail text such as a stack trace.Returns a formatted timestamp string for display.Returns the human-readable message describing this event.Returns a single-line summary suitable for display in lists.Returns the timestamp when this event occurred.getType()Returns the severity level of this event.toJson()Converts this entry to a JSON string for file persistence.
Constructor Details
LogEntry
public LogEntry(Instant timestamp, IP2LocationEventLog.EventType type, IP2LocationEventLog.EventCategory category, String message, String detail) Creates a log entry.- Parameters:
timestamp- The time when this event occurredtype- The severity levelcategory- The event categorymessage- The event messagedetail- Optional detail text (may be null)
Method Details
getTimestamp
Returns the timestamp when this event occurred.- Returns:
- The event timestamp
getType
Returns the severity level of this event.- Returns:
- The event type (INFO, WARNING, or ERROR)
getCategory
Returns the category/classification of this event.- Returns:
- The event category
getMessage
Returns the human-readable message describing this event.- Returns:
- The event message
getDetail
Returns optional detail text such as a stack trace.- Returns:
- The detail text, or
nullif none
getFormattedTimestamp
Returns a formatted timestamp string for display.Format: "yyyy-MM-dd HH:mm:ss" in the system's default timezone.
- Returns:
- The formatted timestamp string
getSummary
Returns a single-line summary suitable for display in lists.Format: "[timestamp] TYPE: message"
- Returns:
- The summary string
toJson
Converts this entry to a JSON string for file persistence.The JSON format is a single line with no pretty-printing, suitable for JSON-lines file format.
- Returns:
- The JSON representation of this entry
fromJson
Parses a log entry from a JSON string.This is the inverse of
toJson(). If the JSON is malformed or missing required fields, returnsnull.- Parameters:
json- The JSON string to parse- Returns:
- The parsed LogEntry, or
nullif parsing failed