Package org.daiitech.naftah.utils
Class JulLoggerConfig
java.lang.Object
org.daiitech.naftah.utils.JulLoggerConfig
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 -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to prevent instantiation. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidinitialize(InputStream configFile) Initializes the Java Util Logging framework from the given InputStream configuration.static voidinitialize(String propertiesPath) Initializes the logging configuration from an external properties file path.static voidinitializeFromResources(String propertiesPath) Initializes the logging configuration from a properties file located in the classpath resources.
-
Field Details
-
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
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 aNaftahBugErrorwhen called.
-
-
Method Details
-
initialize
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
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 readFileNotFoundException- if the resource cannot be found
-
initialize
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
-