Class ConfigLoader

java.lang.Object
com.log4rich.config.ConfigLoader

public class ConfigLoader extends Object
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 Details

    • loadConfiguration

      public static Configuration 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

      public static Configuration loadConfiguration(String filePath) throws IOException
      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 read
      IllegalArgumentException - if filePath is null or empty
      FileNotFoundException - 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

      public static String[] getSearchPaths()
      Gets the search paths for configuration files. Returns human-readable descriptions of all search locations.
      Returns:
      array of search path descriptions