Class: UniqLogger::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/uniq_logger/configuration.rb

Class Method Summary collapse

Class Method Details

.configObject



55
56
57
# File 'lib/uniq_logger/configuration.rb', line 55

def self.config
  @config
end

.configure(opts = {}) ⇒ Object

Configure through hash



31
32
33
# File 'lib/uniq_logger/configuration.rb', line 31

def self.configure(opts = {})
  opts.each {|k,v| @config[k.to_s] = v if @valid_config_keys.include? k.to_s}
end

.configure_with_pathObject

Configure through yaml file



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/uniq_logger/configuration.rb', line 36

def self.configure_with_path
  if defined?(::Rails).nil?
    path_to_yaml_file = "../config/uniq_logger.yml"
  else
    path_to_yaml_file = "#{::Rails.root}/config/uniq_logger.yml"
  end
  begin
    config = YAML::load(IO.read(path_to_yaml_file))
  rescue Errno::ENOENT
    puts "YAML configuration file couldn't be found. Using defaults."
    return
  rescue Psych::SyntaxError
    puts "YAML configuration file contains invalid syntax. Using defaults."
    return
  end

  configure(config)
end