Ruby on rails 3 如何通过yaml在log4r中创建自定义级别

Ruby on rails 3 如何通过yaml在log4r中创建自定义级别,ruby-on-rails-3,configuration,yaml,log4r,Ruby On Rails 3,Configuration,Yaml,Log4r,我有一个Rails 4.1应用程序,使用通过yaml配置的log4r 1.1.10,一切正常。现在我只想添加一个自定义级别。因此,在yaml文件的顶部,我在log4r\u config之后添加了七行: log4r_config: pre_config: custom_levels: - INFO - WARN - ERROR - SERIOUS - FATAL # define all loggers ... log

我有一个Rails 4.1应用程序,使用通过yaml配置的log4r 1.1.10,一切正常。现在我只想添加一个自定义级别。因此,在yaml文件的顶部,我在
log4r\u config
之后添加了七行:

log4r_config:
  pre_config:
    custom_levels:
      - INFO
      - WARN
      - ERROR
      - SERIOUS
      - FATAL
  # define all loggers ...
  loggers:
my application.rb的相关部分如下所示:

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'] )
但当我现在启动应用程序时,我得到了

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)>'
ArgumentError:日志级别必须为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`'

在yaml中定义自定义log4r级别的正确方法是什么?

解决方案永远不会忽略调试级别。这只是我的疏忽。由于Log4r使用调试级别来编写调试消息,因此忽略它是非常糟糕的。

似乎Log4r本身使用了一种方法来编写调试消息。自定义级别在中运行良好。你要用Log4r替换Rails记录器吗?我确实要用Log4r替换Rails记录器。一旦我加入了调试,自定义级别对我来说就很好了。我没有笔记,甚至没有原始的application.rb文件,但调试的参考完全可能来自我自己的log4r.yml文件。如果您在开发模式下用log4r替换了Rails logger,当机架尝试访问
Rails.logger.format
时,使用Rails 4.1应该会发生错误。我最近创建了一个名为的新fork,以使log4r与rails更加兼容,特别是对于最新的rails。