Class: Ixtlan::Rails::DumpError

Inherits:
Object
  • Object
show all
Defined in:
lib/ixtlan/rails/error_handling.rb

Instance Method Summary collapse

Constructor Details

#initialize(email_from = nil, email_to = nil, errors_dir = nil) ⇒ DumpError

Returns a new instance of DumpError.



79
80
81
82
83
84
85
# File 'lib/ixtlan/rails/error_handling.rb', line 79

def initialize(email_from = nil, email_to = nil, errors_dir = nil)
  errors_dir ||= "#{RAILS_ROOT}/log/errors"
  FileUtils.mkdir_p(errors_dir || "#{RAILS_ROOT}/log/errors")
  @errors_dir = Dir.new(errors_dir)
  @email_from = email_from
  @email_to = email_to
end

Instance Method Details

#dump(controller, exception) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ixtlan/rails/error_handling.rb', line 87

def dump(controller, exception)
  time = Time.now
  error_log_id = "#{time.tv_sec}#{time.tv_usec}"

  log_file = File.join(@errors_dir.path.to_s, "error-#{error_log_id}.log")
  logger = Logger.new(log_file)

  dump_environment(logger, exception, controller)
  ::Ixtlan::Mailer.deliver_error_notification(@email_from, @email_to, exception, log_file) unless (@email_to.blank? || @email_from.blank?)
  log_file
end