fowlball1010
fowlball1010

Reputation: 383

Log4r Yaml Configuration Dymamically Change

I'm trying to use Log4r in ruby for logging purposes. I would like to be able to dynamically change the yaml configuration file for the logger on the fly (example: log level) and have that change automatically propagate through to the logger. I know the documentation Log4r documentation states that:

"Dynamically redefining levels, tracing or additivity is expensive. It's best to set up all your loggers in a config script and avoid making dynamic changes to Log4r objects."

However, is there any way to be able to do this? I've found code I would like to mimic here:

def check_config
  # auto reload config every 30 seconds.
  return unless check_again?
  detect_existing_config_path
  return if File.mtime(@config_path) == @config_time
  Log4r::YamlConfigurator.load_yaml_file @config_path
  @config_time = File.mtime(@config_path)
  rescue Log4r::ConfigError => e
    puts "Log4r Error: Unable to load config #{@config_path}, error: #{e}."
end

The above code is from the link with the specific function I'm focused on. However, calling Log4r::YamlConfiguration.load_yaml_file @config_path seems to not update the logger dynamically. Anyone have any experience/recommendations for changing Log4r config properties on the fly?

Upvotes: 1

Views: 159

Answers (0)

Related Questions