0

我有一个使用通过 yaml 配置的 log4r 1.1.10 的 Rails 4.1 应用程序,一切正常。现在我只想添加一个自定义级别。所以在我的 yaml 文件的顶部,我在后面添加了七行log4r_config

log4r_config:
  pre_config:
    custom_levels:
      - INFO
      - WARN
      - ERROR
      - SERIOUS
      - FATAL
  # define all loggers ...
  loggers:

我的 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)>'

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

4

1 回答 1

0

解决方案是永远不要忽略 DEBUG 级别。这只是我的疏忽。由于 Log4r 使用调试级别来编写调试消息,因此将其排除在外是非常糟糕的。

于 2014-12-17T15:09:51.677 回答