我正在使用 XML 配置文件设置 Log4r,但无法让 EmailOutputter 正常工作。这是我的输出器标签:
<outputter type="EmailOutputter" name="exception_email" trunc="false" level="ERROR" buffsize="10">
<formatter type="PatternFormatter" pattern="#{pattern}"/>
<server>#{smtp_address}</server>
<port>#{smtp_port}</port>
<domain>#{smtp_domain}</domain>
<from>logging@#{smtp_domain}</from>
<to>exceptions@mydomain.com</to>
<subject>Log Report</subject>
<immediate_at>ERROR, FATAL</immediate_at>
</outputter>
我已经使用 RubyMine 逐步调试器对所有 XML 变量进行了三重和四重检查。异常消息是:
未捕获的异常:创建输出器时出现问题:未初始化的常量 Log4r::Configurator::EmailOutputter /usr/local/lib/ruby/gems/1.9.1/gems/log4r-1.1.10/lib/log4r/configurator.rb:87:inblock in decode_xml'
/usr/local/lib/ruby/1.9.1/rexml/element.rb:905:in
阻止每个' /usr/local/lib/ruby/1.9.1/rexml/xpath.rb:67:ineach'
/usr/local/lib/ruby/1.9.1/rexml/xpath.rb:67:in
每个' /usr/local/lib/ruby/1.9.1/rexml/element.rb:905:in each'
/usr/local/lib/ruby/gems/1.9.1/gems/log4r-1.1.10/lib/log4r/configurator.rb:87:in
decode_xml' /usr/local/lib/ruby/gems/1.9.1/gems/log4r-1.1.10/lib/log4r/configurator.rb:82:in actual_load'
/usr/local/lib/ruby/gems/1.9.1/gems/log4r-1.1.10/lib/log4r/configurator.rb:56:in
load_xml_file' /root/src/upside/common/upside_logger.rb :16:in initialize'
/root/src/upside/common/logger_factory.rb:7:in
new' /root/src/upside/common/logger_factory.rb:7:in new_logger'
/root/src/upside/config/application.rb:30:in
block in ' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/ active_support/lazy_load_hooks.rb:34:incall'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:34:in
execute_hook' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:26:in block in on_load'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:25:in
each' /usr/local/lib/ruby/gems/1.9 .1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:25:in on_load'
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configuration.rb:43:in
before_configuration' /root/src/upside/config/application.rb:29:in <class:Application>'
/root/src/upside/config/application.rb:15:in
' /root/src/upside/config/ application.rb:14:in<top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:53:in
需要'/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:53:in block in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:50:in
tap'/usr/local/ lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:50:in <top (required)>'
/root/src/upside/script/rails:6:in
require' /root/src/upside/script/rails:6:in `'
我已经仔细检查了 gem 安装,并且 emailoutputter.rb 与其他输出器(功能正常)位于正确的目录中。
谢谢!