Log4r配置程序抛出异常实例化EmailOutputter

时间:2014-01-14 17:06:16

标签: ruby-on-rails log4r

我正在使用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:in block 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:in each' /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阻止'     /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:34:in call' /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 require'     /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点击'     /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:在`'

我已经仔细检查了gem安装,并且emailoutputter.rb与其他输出器(功能正常)位于正确的目录中。

谢谢!

1 个答案:

答案 0 :(得分:1)

我发现log4r文件lib/log4r.rb缺少行require "log4r/outputter/emailoutputter"。将此缺少的require添加到config/initializer文件中的Rails应用程序中,可以使EmailOutputter类可用。