I'm setting up Log4r using an XML configuration file, and I can't get the EmailOutputter to work correctly. Here's my outputter tag:
<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>
I've triple and quadruple checked that all the XML variables are being passed in correctly using the RubyMine step-through debugger. The exception message is:
Uncaught exception: Problem creating outputter: uninitialized constant 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
block in each'
/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
each'
/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: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
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 `'
I've double checked the gem installation and the emailoutputter.rb is in the correct directory with the other outputters (which function correctly).
Thanks!
I found that the log4r file lib/log4r.rb
to be missing the line require "log4r/outputter/emailoutputter"
. Adding this missing require
to my Rails application in a config/initializer
file allowed the EmailOutputter class available.