Class ClasspathJulConfig
java.lang.Object
zeroecho.logging.ClasspathJulConfig
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
SecurityExceptionorIOExceptionoccurs while applying the configuration, the exception stack trace is printed directly toSystem.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 Summary
ConstructorsConstructorDescriptionLoadsjul.propertiesfrom the classpath and applies it as the currentLogManagerconfiguration. -
Method Summary
-
Constructor Details
-
ClasspathJulConfig
public ClasspathJulConfig()Loadsjul.propertiesfrom the classpath and applies it as the currentLogManagerconfiguration.- Throws:
IllegalStateException- if the resourcejul.propertiesis not found
-