Class ConfigurationManager

java.lang.Object
com.log4rich.config.ConfigurationManager

public class ConfigurationManager extends Object
Manages runtime configuration changes for the log4Rich framework. Provides thread-safe methods to modify configuration at runtime. This class serves as the central point for all configuration management and automatically applies changes to the logging system.
  • Method Details

    • initialize

      public static void initialize(Configuration config)
      Initializes the configuration manager with the current configuration. This method sets up the configuration and applies it to all loggers.
      Parameters:
      config - the configuration to use
    • getCurrentConfiguration

      public static Configuration getCurrentConfiguration()
      Gets the current configuration. This method is thread-safe and returns a reference to the current configuration.
      Returns:
      the current configuration, or null if not initialized
    • setRootLevel

      public static void setRootLevel(LogLevel level)
      Sets the root logger level. This affects all loggers that don't have specific levels configured. Changes take effect immediately if auto-apply is enabled.
      Parameters:
      level - the new root level to set
    • setLocationCapture

      public static void setLocationCapture(boolean enabled)
      Sets the location capture setting globally. When enabled, the framework will capture and include class name, method name, and line number information in log events.
      Parameters:
      enabled - true to enable location capture, false to disable
    • setLoggerLevel

      public static void setLoggerLevel(String loggerName, LogLevel level)
      Sets a specific logger's level. This overrides the root level for the specified logger.
      Parameters:
      loggerName - the name of the logger to configure
      level - the level to set for this logger
    • setConsoleEnabled

      public static void setConsoleEnabled(boolean enabled)
      Enables or disables console logging. When enabled, log messages will be written to the console.
      Parameters:
      enabled - true to enable console logging, false to disable
    • setConsoleTarget

      public static void setConsoleTarget(String target)
      Sets the console target stream.
      Parameters:
      target - the target stream ("STDOUT" or "STDERR")
    • setConsolePattern

      public static void setConsolePattern(String pattern)
      Sets the console logging pattern. The pattern defines how log messages are formatted for console output.
      Parameters:
      pattern - the pattern string (e.g., "[%level] %date %message%n")
    • setFileEnabled

      public static void setFileEnabled(boolean enabled)
      Enables or disables file logging. When enabled, log messages will be written to the configured file.
      Parameters:
      enabled - true to enable file logging, false to disable
    • setFilePath

      public static void setFilePath(String filePath)
      Sets the file path for logging. This changes where log messages are written.
      Parameters:
      filePath - the path to the log file
    • setFilePattern

      public static void setFilePattern(String pattern)
      Sets the file logging pattern. The pattern defines how log messages are formatted for file output.
      Parameters:
      pattern - the pattern string (e.g., "[%level] %date %message%n")
    • setMaxFileSize

      public static void setMaxFileSize(String maxSize)
      Sets the maximum file size for rolling. When the log file reaches this size, it will be rolled over.
      Parameters:
      maxSize - the maximum size (e.g., "10M", "100K", "1G")
    • setMaxBackups

      public static void setMaxBackups(int maxBackups)
      Sets the maximum number of backup files. When rolling over, this many backup files will be kept.
      Parameters:
      maxBackups - the maximum number of backup files to keep
    • setCompression

      public static void setCompression(boolean enabled, String program, String args)
      Sets compression settings for rolled log files. When enabled, rolled log files will be compressed using the specified program.
      Parameters:
      enabled - true to enable compression, false to disable
      program - the compression program to use (e.g., "gzip", "bzip2")
      args - the arguments for the compression program
    • createConsoleAppender

      public static ConsoleAppender createConsoleAppender(String name, String target, String pattern)
      Creates a new console appender with the specified settings. The appender will be managed by the framework and can be retrieved by name.
      Parameters:
      name - the name of the appender
      target - the target stream ("STDOUT" or "STDERR")
      pattern - the pattern to use for formatting, or null for default
      Returns:
      the created console appender
    • createRollingFileAppender

      public static RollingFileAppender createRollingFileAppender(String name, String filePath, String maxSize, int maxBackups, String pattern)
      Creates a new rolling file appender with the specified settings. The appender will be managed by the framework and can be retrieved by name.
      Parameters:
      name - the name of the appender
      filePath - the path to the log file
      maxSize - the maximum file size (e.g., "10M", "100K")
      maxBackups - the maximum number of backup files
      pattern - the pattern to use for formatting, or null for default
      Returns:
      the created rolling file appender
    • getManagedAppender

      public static Appender getManagedAppender(String name)
      Gets a managed appender by name.
      Parameters:
      name - the name of the appender
      Returns:
      the appender, or null if not found
    • removeManagedAppender

      public static Appender removeManagedAppender(String name)
      Removes a managed appender. The appender will be closed and can no longer be used.
      Parameters:
      name - the name of the appender to remove
      Returns:
      the removed appender, or null if not found
    • reloadConfiguration

      public static void reloadConfiguration() throws Exception
      Reloads configuration from the original source. This re-reads the configuration file and applies any changes.
      Throws:
      Exception - if configuration cannot be reloaded
    • setAutoApplyConfiguration

      public static void setAutoApplyConfiguration(boolean autoApply)
      Sets whether configuration changes should be automatically applied. When disabled, changes must be applied manually using applyCurrentConfiguration().
      Parameters:
      autoApply - true to automatically apply configuration changes, false otherwise
    • applyCurrentConfiguration

      public static void applyCurrentConfiguration()
      Manually applies the current configuration. This method is useful when auto-apply is disabled.
    • getStats

      public static ConfigurationManager.ConfigurationStats getStats()
      Gets statistics about the current configuration. Provides information about the current state of the logging system.
      Returns:
      configuration statistics including logger and appender counts
    • shutdown

      public static void shutdown()
      Shuts down the configuration manager and cleans up all managed appenders. This method closes all managed appenders and clears the configuration.