Class JsonLineFormatter

java.lang.Object
java.util.logging.Formatter
org.egothor.methodatlas.JsonLineFormatter

public final class JsonLineFormatter extends Formatter
Formatter that emits one JSON object per log record, on a single line, suitable for ingestion by log-aggregation pipelines (Elastic, Splunk, Loki) and for reproducible audit-trail archives.

Acts as the JUL-native equivalent of an SLF4J / Logback JSON encoder. The MethodAtlas codebase stays on the classic java.util.logging stack (no SLF4J / Log4j dependency) per project convention; this formatter delivers structured-logging semantics without adding any third-party logging library.

Output schema

Each LogRecord becomes one line of UTF-8 text containing a JSON object with the following fields:

  • timestamp — ISO-8601 instant (2026-05-27T13:45:06Z)
  • level — JUL level name (INFO, WARNING, …)
  • logger — full logger name from LogRecord.getLoggerName()
  • thread — name of the thread that emitted the record
  • message — the formatted log message (with parameters interpolated)
  • runId — short correlation id from ScanRunContext, omitted when no run is set on the current thread
  • thrown — string-rendered exception stack trace, present only when LogRecord.getThrown() is non-null

Activation

The formatter is not installed automatically. Activate it through a JUL configuration file (commonly via the -Djava.util.logging.config.file system property), or programmatically by attaching the formatter to a Handler:


 Handler handler = new ConsoleHandler();
 handler.setFormatter(new JsonLineFormatter());
 Logger.getLogger("org.egothor.methodatlas").addHandler(handler);
 

Thread safety

The formatter is stateless and safe for concurrent use by multiple handlers and threads.

Since:
1.0.0
See Also:
  • Constructor Details

    • JsonLineFormatter

      public JsonLineFormatter()
      Creates a new formatter. The class carries no instance state and is safe to share across handlers.
  • Method Details

    • format

      public String format(LogRecord record)
      Renders record as a single line of JSON terminated by \n. The exact field set is documented on the class.
      Specified by:
      format in class Formatter
      Parameters:
      record - log record to render; must not be null
      Returns:
      JSON-encoded log entry followed by a newline