Package com.log4rich.config
Class ConfigLoader
java.lang.Object
com.log4rich.config.ConfigLoader
Loads configuration from various sources in the search order specified.
Implements the configuration file search logic with multiple fallback locations.
This class handles caching and provides utility methods for configuration discovery.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Clears the cached configuration to force reload.static boolean
Checks if a configuration file exists in any of the search locations.static String[]
Gets the search paths for configuration files.static Configuration
Loads configuration from the first available source.static Configuration
loadConfiguration
(String filePath) Loads configuration from a specific file.
-
Method Details
-
loadConfiguration
Loads configuration from the first available source. The configuration is cached after the first load to improve performance. Search order: 1. System property: -Dlog4rich.config=/path/to/config 2. Classpath: log4Rich.config (root of classpath) 3. Current directory: ./log4Rich.config 4. Parent directory: ../log4Rich.config 5. Config directories: - ./config/log4Rich.config - ./conf/log4Rich.config - ../config/log4Rich.config - ../conf/log4Rich.config 6. Default configuration if no file is found- Returns:
- configuration object with settings loaded from the first available source
-
loadConfiguration
Loads configuration from a specific file. This method bypasses the search order and loads directly from the specified file.- Parameters:
filePath
- path to the configuration file- Returns:
- configuration object with settings loaded from the file
- Throws:
IOException
- if file cannot be readIllegalArgumentException
- if filePath is null or emptyFileNotFoundException
- if the file does not exist
-
clearCache
public static void clearCache()Clears the cached configuration to force reload. The next call to loadConfiguration() will re-read the configuration from disk. -
configExists
public static boolean configExists()Checks if a configuration file exists in any of the search locations. This method follows the same search order as loadConfiguration().- Returns:
- true if a configuration file is found, false otherwise
-
getSearchPaths
Gets the search paths for configuration files. Returns human-readable descriptions of all search locations.- Returns:
- array of search path descriptions
-