Home > Software engineering >  How does the rails logger need to be setup to send emails for all errors and fatals?
How does the rails logger need to be setup to send emails for all errors and fatals?

Time:02-25

I can't seem to find how to setup rails 6 in a way that the logger sends an e-mail for all errors and fatal errors; i found loads of topics on how to customize the log messages themselves (and how to log emails that the app sends), but is there a way to connect actionmailer to the logger?

Thanks!

CodePudding user response:

I recommend using something like this gem https://github.com/smartinez87/exception_notification to log errors.

However, you could achieve what you're asking for with a custom logger

class MailerLogger < Logger
  def add(severity, message = nil, progname = nil)
    if severity == Logger::Severity::FATAL
      # Send email here
    end
    super(severity, message, progname)
  end
end

# config/application.rb or config/environments/production.rb

config.logger = MailerLogger.new(STDOUT)
  • Related