Skip to content

Instantly share code, notes, and snippets.

@toshiyukihina
Created March 29, 2016 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toshiyukihina/fa341e3490dd54df4c48 to your computer and use it in GitHub Desktop.
Save toshiyukihina/fa341e3490dd54df4c48 to your computer and use it in GitHub Desktop.
utility module for backtrace
module Backtracable
def self.included(klass)
klass.class_eval do
include InstanceMethods
end
end
module InstanceMethods
def backtrace(e: nil, logger: Rails.logger, method: :warn)
e.nil? ? backtrace_info(logger, method) : backtrace_via_exception(e, logger, method)
end
def backtrace_via_exception(e, logger, method)
logger.send(method, e.to_s)
logger.send(method, e.backtrace.join("\n"))
end
def backtrace_info(logger, method)
logger.send(method, caller.join("\n"))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment