Class ClasspathJulConfig

java.lang.Object
zeroecho.logging.ClasspathJulConfig

public final class ClasspathJulConfig extends Object
Configures java.util.logging (JUL) from a jul.properties resource on the classpath.

When constructed, this class attempts to locate jul.properties using the current thread’s context class loader. If none is available, it falls back to the defining class loader. The located resource is then parsed by LogManager.readConfiguration(InputStream) to install JUL handlers, formatters, and levels as specified.

Error handling

  • If the resource is not found, construction fails with IllegalStateException.
  • If a SecurityException or IOException occurs while applying the configuration, the exception stack trace is printed directly to System.err. This ensures diagnostic visibility even before JUL itself is configured.

JSON structured logging

When the system property zeroecho.logging.json is set to true before construction, a JsonLogFormatter is installed on every handler attached to the root logger. Each record is then emitted as a single-line JSON object, making log ingestion by Splunk, ELK, or Datadog trivial without grok patterns.

Usage

// Enable JSON output before initialising logging:
System.setProperty("zeroecho.logging.json", "true");
new ClasspathJulConfig();

// Afterwards, all log records are emitted as newline-delimited JSON.
Logger log = Logger.getLogger("my.app");
log.info("Configured via classpath resource");
Since:
1.0
  • Constructor Details

    • ClasspathJulConfig

      public ClasspathJulConfig()
      Loads jul.properties from the classpath and applies it as the current LogManager configuration.
      Throws:
      IllegalStateException - if the resource jul.properties is not found