<commit_before>module Exceptionally
  class Handler
    def initialize(message = nil, status = nil, e = nil, params = nil)
      @message = message
      @status = status || 500
      @error = e
      @params = params || {}

      @@callback.call(@message, @status, @error, @params) if defined?(@@callback) && @@callback.respond_to?(:call)
      log
    end

    def self.before_render(&block)
      @@callback = Proc.new(&block)
    end

    def log
      # Log 5xx errors
      if @status >= 500 && @error
        # Support Airbrake and New Relic out of box
        Airbrake.notify(@error, :parameters => @params) if defined?(Airbrake) && Airbrake.respond_to?(:notify) && Rails.env.production?
        NewRelic::Agent.notice_error(@error) if defined?(NewRelic) && defined?(NewRelic::Agent) && NewRelic::Agent.respond_to?(:notice_error) && Rails.env.production?

        Rails.logger.error(@error.to_s)
        Rails.logger.error("Parameters: #{@params.to_s}") unless @params.blank?
        Rails.logger.error(@error.backtrace.join("\n")) unless @error.backtrace.blank?
      end
    end
  end  
end<commit_msg>Slight code cleanup<commit_after>module Exceptionally
  class Handler
    def initialize(message = nil, status = nil, e = nil, params = nil)
      @message = message
      @status = status || 500
      @error = e
      @params = params || {}

      @@callback.call(@message, @status, @error, @params) if defined?(@@callback) && @@callback.respond_to?(:call)
      log
    end

    def self.before_render(&block)
      @@callback = Proc.new(&block)
    end

    def log
      # Log 5xx errors
      if @status >= 500 && @error
        # Support Airbrake and New Relic out of box, but only in production
        if Rails.env.production?
          Airbrake.notify(@error, :parameters => @params) if defined?(Airbrake) && Airbrake.respond_to?(:notify)
          NewRelic::Agent.notice_error(@error) if defined?(NewRelic) && defined?(NewRelic::Agent) && NewRelic::Agent.respond_to?(:notice_error)
        end

        Rails.logger.error(@error.to_s)
        Rails.logger.error("Parameters: #{@params.to_s}") unless @params.blank?
        Rails.logger.error(@error.backtrace.join("\n")) unless @error.backtrace.blank?
      end
    end
  end  
end
{'fraction_non_alphanumeric': 0.1411451398135819, 'fraction_numerical': 0.006213936972924989, 'mean_word_length': 3.025, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4795689', 'n_tokens_mistral': 722, 'n_tokens_neox': 694, 'n_words': 162}