Skip to content

LEVEL can't be passed as parameter to yaml cfg file #42

@cmoulliard

Description

@cmoulliard

If I would like to externalize the logging level using by example a variable with the name "LOGGING_LEVEL" as such within the yml config file

log4r_config:
  # define all loggers ...
  loggers:
    - name      : production
      level        :  "#{LOGGING_LEVEL}"

Code

      if level.nil?
        cfg['LOGGING_LEVEL'] = 'INFO'
      else
        cfg['LOGGING_LEVEL'] = levels[level]
      end

      cfg.decode_yaml log4r_f['log4r_config']

then log4r raise the following exception


/Users/chmoulli/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/log4r-1.1.10/lib/log4r/yamlconfigurator.rb:189:in `decode_logger_common': Log level must be in 0..7 (ArgumentError)
    from /Users/chmoulli/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/log4r-1.1.10/lib/log4r/yamlconfigurator.rb:175:in `decode_logger'
    from /Users/chmoulli/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/log4r-1.1.10/lib/log4r/yamlconfigurator.rb:69:in `block in decode_yaml'
    from /Users/chmoulli/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/log4r-1.1.10/lib/log4r/yamlconfigurator.rb:69:in `each'
    from /Users/chmoulli/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/log4r-1.1.10/lib/log4r/yamlconfigurator.rb:69:in `decode_yaml'
    from /Users/chmoulli/MyProjects/hyla/lib/hyla/logger2.rb:37:in `initialize'

It seems that the file is parsed first with the hash{variable} and replacement is done after the parsing but of course that fails for the LEVEL as it tries to read the string of the hash string

screenshot 2015-03-27 13 58 01

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions