Sha256: b136c7b5790b4d7716e7239e0c065463c9482413d303fc8b0a8b7ffa0726b57e

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

module Tartarus::Logger
  def self.included(base)
    base.extend ClassMethods
    base.serialize :request
  end

  module ClassMethods
    def log(controller, exception)
      create do |logged_exception|
        group_id = "#{exception.class.name}#{exception.message}#{controller.controller_path}#{controller.action_name}" 
    
        logged_exception.exception_class = exception.class.name
        logged_exception.controller_path = controller.controller_path
        logged_exception.action_name = controller.action_name
        logged_exception.message = exception.message
        logged_exception.backtrace = exception.backtrace * "\n"
        logged_exception.request = normalize_request_data(controller.request)
        logged_exception.group_id = Digest::SHA1.hexdigest(group_id)
      end
    end

    def normalize_request_data(request)
      enviroment = request.env.dup

      request_details = {
        :enviroment => { :process => $$, :server => `hostname -s`.chomp },
        :session => { :variables => enviroment['rack.session'].to_hash, :cookie => enviroment['rack.request.cookie_hash'] },
        :http_details => { 
          :method => request.method.to_s.upcase,
          :url => "#{request.protocol}#{request.env["HTTP_HOST"]}#{request.request_uri}",
          :format => request.format.to_s,
          :parameters => request.parameters
        }
      }

      enviroment.each_pair do |key, value|
        request_details[:enviroment][key.downcase] = value if key.match(/^[A-Z_]*$/)
      end

      return request_details
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tartarus-1.0.1 lib/tartarus/logger.rb