Class JulLoggerConfig

java.lang.Object
org.daiitech.naftah.utils.JulLoggerConfig

public final class JulLoggerConfig extends Object
Utility class for initializing Java Util Logging (JUL) configuration.

Provides methods to initialize logging configuration from external property files or resources within the classpath. Ensures that the configuration is loaded only once.

Supports creating log file directories and files if they do not already exist.

Author:
Chakib Daii
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static boolean
     
    static final String
    The system property key used by the Java Logging API to locate the logging configuration file.
    static final String
    The default name of the Java logging configuration file.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Private constructor to prevent instantiation.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    initialize(InputStream configFile)
    Initializes the Java Util Logging framework from the given InputStream configuration.
    static void
    initialize(String propertiesPath)
    Initializes the logging configuration from an external properties file path.
    static void
    Initializes the logging configuration from a properties file located in the classpath resources.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • JAVA_LOGGING_FILE_PROPERTY

      public static final String JAVA_LOGGING_FILE_PROPERTY
      The system property key used by the Java Logging API to locate the logging configuration file.

      Example usage: System.setProperty(JAVA_LOGGING_FILE_PROPERTY, LOGGING_FILE);

      See Also:
    • LOGGING_FILE

      public static final String LOGGING_FILE
      The default name of the Java logging configuration file.

      This file should typically be located on the classpath or in the working directory.

      See Also:
    • initialized

      private static boolean initialized
  • Constructor Details

    • JulLoggerConfig

      private JulLoggerConfig()
      Private constructor to prevent instantiation. Always throws a NaftahBugError when called.
  • Method Details

    • initialize

      public static void initialize(String propertiesPath) throws IOException
      Initializes the logging configuration from an external properties file path. This method is synchronized to prevent multiple initializations.
      Parameters:
      propertiesPath - the file system path to the logging properties file
      Throws:
      IOException - if the properties file cannot be loaded or read
    • initializeFromResources

      public static void initializeFromResources(String propertiesPath) throws IOException
      Initializes the logging configuration from a properties file located in the classpath resources. Ensures that the log file specified by the "java.util.logging.FileHandler.pattern" property exists, creating parent directories and the file itself if necessary. This method is synchronized to prevent multiple initializations.
      Parameters:
      propertiesPath - the resource path to the logging properties file within the classpath
      Throws:
      IOException - if the properties file cannot be found, loaded, or read
      FileNotFoundException - if the resource cannot be found
    • initialize

      public static void initialize(InputStream configFile) throws IOException
      Initializes the Java Util Logging framework from the given InputStream configuration. This method only performs initialization once; subsequent calls are ignored.
      Parameters:
      configFile - InputStream of the logging properties configuration
      Throws:
      IOException - if there is an error reading the configuration