Module: Squash::Ruby

Defined in:
lib/squash/rails.rb

Defined Under Namespace

Modules: ControllerMethods

Class Method Summary collapse

Class Method Details

.client_nameObject



46
# File 'lib/squash/rails.rb', line 46

def self.client_name() 'rails' end

.exception_info_hash_with_rails(exception, *other_args) ⇒ Object Also known as: exception_info_hash

Unwrap ActiveRecord::StatementInvalid, since it’s “special”



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/squash/rails.rb', line 49

def self.exception_info_hash_with_rails(exception, *other_args)
  hsh = exception_info_hash_without_rails(exception, *other_args)

  if defined?(ActiveRecord::StatementInvalid) && exception.kind_of?(ActiveRecord::StatementInvalid)
    if hsh['message'] =~ /^([A-Za-z0-9:_]+?): /
      hsh['message'].sub! /^([A-Za-z0-9:_]+?): /, ''
      hsh['class_name'] = $1
    end
  end

  hsh
end

.failsafe_log(tag, message) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/squash/rails.rb', line 32

def self.failsafe_log(tag, message)
  logger = Rails.respond_to?(:logger) ? Rails.logger : RAILS_DEFAULT_LOGGER
  if (logger.respond_to?(:tagged))
    logger.tagged(tag) { logger.error message }
  else
    logger.error "[#{tag}]\t#{message}"
  end
rescue Object => err
  $stderr.puts "Couldn't write to failsafe log (#{err.to_s}); writing to stderr instead."
  $stderr.puts "#{Time.now.to_s}\t[#{tag}]\t#{message}"
end