Class JsonLogFormatter

java.lang.Object
io.github.jspinak.brobot.logging.formatter.JsonLogFormatter
All Implemented Interfaces:
LogFormatter

@Component public class JsonLogFormatter extends Object implements LogFormatter
JSON log formatter for machine processing.

Produces structured JSON output suitable for log aggregation systems, SIEM tools, and automated log analysis. The JSON format preserves all data types and allows for easy querying and filtering.

Output structure:


 {
   "@timestamp": "2023-12-01T14:23:45.123Z",
   "@version": "1",
   "category": "ACTIONS",
   "level": "INFO",
   "message": "Clicked submit button",
   "thread": "main",
   "correlation": {
     "id": "abc123",
     "session": "xyz789",
     "operation": "user-login"
   },
   "action": {
     "type": "CLICK",
     "target": "submitButton",
     "success": true
   },
   "timing": {
     "duration": 25,
     "startTime": "2023-12-01T14:23:45.098Z"
   },
   "location": {
     "x": 150,
     "y": 300
   },
   "performance": {
     "memory": 1048576,
     "operations": 1
   },
   "metadata": {
     "custom": "value"
   }
 }
 

Features:

  • ELK Stack compatible format
  • ISO 8601 timestamps with @timestamp field
  • Hierarchical structure for related fields
  • Type preservation (numbers, booleans, strings)
  • Complete metadata inclusion
  • Error details with stack traces
  • Compact JSON without pretty printing
  • Constructor Details

    • JsonLogFormatter

      public JsonLogFormatter()
  • Method Details

    • format

      public String format(LogEntry entry)
      Description copied from interface: LogFormatter
      Format a log entry into a string.
      Specified by:
      format in interface LogFormatter
      Parameters:
      entry - The log entry to format
      Returns:
      The formatted string representation
    • getFormatType

      public LogFormatter.FormatType getFormatType()
      Description copied from interface: LogFormatter
      Get the expected output format type. Used for routing to appropriate output destinations.
      Specified by:
      getFormatType in interface LogFormatter
      Returns:
      The format type
    • getName

      public String getName()
      Description copied from interface: LogFormatter
      Get the name of this formatter for identification.
      Specified by:
      getName in interface LogFormatter
      Returns:
      The formatter name