我正在使用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与其他输出器(功能正常)位于正确的目录中。
谢谢!
答案 0 :(得分:1)
我发现log4r文件lib/log4r.rb
缺少行require "log4r/outputter/emailoutputter"
。将此缺少的require
添加到config/initializer
文件中的Rails应用程序中,可以使EmailOutputter类可用。