Skip to content
This repository was archived by the owner on Jun 14, 2022. It is now read-only.
This repository was archived by the owner on Jun 14, 2022. It is now read-only.

Logging exception outside the context of controller #10

Description

@kamilpogo

I'm using exception logger in classes that are not within a controller context. This is the case for example for resque workers.
Resque workers are classes with a class method named perform in order to perform background jobs. For logging an exception I need a class method that logs exceptions. I include this module to all my workers:

module WorkerExceptionLogger

  def self.included(target)
    target.extend(ClassMethods)
  end

  module ClassMethods
    def log_exception(exception, data = nil)
      message = exception.message.inspect
      message << "\n* Extra Data\n\n#{data}" unless data.blank?
      ExceptionLogger::LoggedException.create! \
          :exception_class => exception.class.name,
          :controller_name => self.to_s,
          :action_name => caller_locations(1, 1)[0].label,
          :message => message,
          :backtrace => exception.backtrace
    end
  end

This method sets "controller_name" to the name of the class and "action_name" to the name of the calling function.

It would be cool to have this functionallity directly in the gem:

  1. class method for logging an exception
  2. universal create_from_exception (i.e. that not only works with conrollers)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions