Class ClasspathConfiguration

java.lang.Object
is.codion.plugin.jul.ClasspathConfiguration

public final class ClasspathConfiguration extends Object
A custom configuration class for java.util.logging that loads configuration files from the classpath.

By default, java.util.logging only supports loading configuration files from the filesystem via -Djava.util.logging.config.file=path/to/file.properties. This limitation makes it difficult to use JUL configuration in containerized applications, jlink images, or fat jars where configuration files are typically packaged as classpath resources.

This class bridges that gap by loading the configuration file specified by java.util.logging.config.file from the classpath instead of the filesystem. It uses the standard JUL configuration mechanism via -Djava.util.logging.config.class to install itself as the configuration handler.

Usage

Place your logging configuration file (e.g., logging.properties) on the classpath and configure the JVM with both properties:


 -Djava.util.logging.config.file=logging.properties
 -Djava.util.logging.config.class=is.codion.plugin.jul.ClasspathConfiguration
 

The configuration file will be loaded from the classpath root using the context class loader.

Example Configuration File

A typical use case is configuring serialization filter rejection logging:


 # logging.properties - place on classpath

 # Global log level
 .level=OFF

 # Enable java.io.serialization logger
 java.io.serialization.level=FINE
 java.io.serialization.handlers=java.util.logging.FileHandler
 java.io.serialization.useParentHandlers=false

 # Write to file in working directory
 java.util.logging.FileHandler.pattern=serialization.log
 java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
 java.util.logging.SimpleFormatter.format=%1$tF %1$tT %4$s: %5$s%n
 

Benefits

  • Works with jlink images where filesystem access may be restricted
  • Compatible with Docker containers and cloud deployments
  • Enables packaging JUL configuration in fat jars
  • Maintains standard java.util.logging.config.file property semantics
  • Provides clear feedback on success or failure to load configuration
See Also:
  • Field Details

    • CONFIGURATION_FILE

      public static final PropertyValue<String> CONFIGURATION_FILE
      The classpath configuration file.
      • Value type: String
      • Default value: null
  • Constructor Details

    • ClasspathConfiguration

      public ClasspathConfiguration()
      Constructs a new ClasspathConfiguration and immediately loads the configuration file specified by java.util.logging.config.file from the classpath.

      This constructor is invoked automatically by the JVM when -Djava.util.logging.config.class=is.codion.plugin.jul.ClasspathConfiguration is specified.

      If the configuration file is found and successfully loaded, a confirmation message is printed to stdout. If the file is not found or loading fails, an error message is printed to stderr.