Sha256: 2cbb24d595ced3089fbdaa5fdbaa7a78177e0fd954e908cd83578c94e1f10ad2

Contents?: true

Size: 1.73 KB

Versions: 5

Compression:

Stored size: 1.73 KB

Contents

module UniqLogger
  class Configuration
    @config = {
              "log_rotator" => "none",
              "log_rotator_prefix" => "uniq_logger-",
              "global_logger" => true,
              "global_log_file_name" => "uniq_logger.log",
              "validates_uniqness_of_id" => true,
              "logfile_destination" => "local",
              "path_to_local_logfiles" => "log",
              "remote" => {
                "auth_token" => "xyz123abc",
                "server" => "http://www.server.de",
                "endpoint" => "/api/v1/logger",
                "url_param_for_id" => "id",
                "url_param_for_data" => "data",
                "basic_auth" => {
                  "username" => "",
                  "password" => ""
                }
              },
              "csv" => {
                "encoding" => "UTF8",
                "col_sep" => ";"
              }
            }

    @valid_config_keys = @config.keys

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

    # Configure through yaml file
    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

    def self.config
      @config
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
uniq_logger-0.1.7 lib/uniq_logger/configuration.rb
uniq_logger-0.1.6 lib/uniq_logger/configuration.rb
uniq_logger-0.1.5 lib/uniq_logger/configuration.rb
uniq_logger-0.1.4 lib/uniq_logger/configuration.rb
uniq_logger-0.1.3 lib/uniq_logger/configuration.rb