I have a Rails 4.1 app using log4r 1.1.10 configured via yaml and everything works fine. Now I just want to add a custom level. So at the top of my yaml file I added seven lines after log4r_config
:
log4r_config:
pre_config:
custom_levels:
- INFO
- WARN
- ERROR
- SERIOUS
- FATAL
# define all loggers ...
loggers:
The relevant part of my application.rb looks like:
require 'log4r'
require 'log4r/yamlconfigurator'
require File.join(File.dirname(__FILE__),"../lib/rollable_file_outputter.rb")
include Log4r
log4r_config = YAML.load_file(File.join(File.dirname(__FILE__),"log4r.yml"))
YamlConfigurator.decode_yaml( log4r_config['log4r_config'] )
But when I launch the app now I get
ArgumentError: Log level must be in 0..7
/opt/thermyos.com/server/shared/bundle/ruby/2.0.0/gems/log4r-1.1.10/lib/log4r/yamlconfigurator.rb:189:in `decode_logger_common'
/opt/thermyos.com/server/shared/bundle/ruby/2.0.0/gems/log4r-1.1.10/lib/log4r/yamlconfigurator.rb:175:in `decode_logger'
/opt/thermyos.com/server/shared/bundle/ruby/2.0.0/gems/log4r-1.1.10/lib/log4r/yamlconfigurator.rb:69:in `block in decode_yaml'
/opt/thermyos.com/server/shared/bundle/ruby/2.0.0/gems/log4r-1.1.10/lib/log4r/yamlconfigurator.rb:69:in `each'
/opt/thermyos.com/server/shared/bundle/ruby/2.0.0/gems/log4r-1.1.10/lib/log4r/yamlconfigurator.rb:69:in `decode_yaml'
/opt/thermyos.com/server/releases/20141209152838/config/application.rb:23:in `<top (required)>'
What's the right way to define custom log4r levels in yaml?
The solution is never leave out the DEBUG level. It was just an oversight on my part. Since Log4r uses the debug level to write debug messages, leaving it out is very bad.