Skip to content

Instantly share code, notes, and snippets.

@thenoseman
Forked from txus/.pryrc.rb
Created June 24, 2013 14:09
Show Gist options
  • Save thenoseman/5850313 to your computer and use it in GitHub Desktop.
Save thenoseman/5850313 to your computer and use it in GitHub Desktop.
def write_backtrace name, backtrace, filename
exceptions = Regexp.union([
/\.bundle/,
/spec/,
/test/,
/lib\/ruby\/1.9.1/
])
backtrace.reject! { |line| line =~ exceptions }
File.open(filename, 'a') do |f|
f.write "* #{name}\n\n" + backtrace.join("\n") + "\n\n"
end
end
# Example usage:
#
# trace Redis::Client#process my_redis_calls.log
#
Pry.commands.block_command(/trace ([^ ]+) ([^ ]+)$/, "Trace a method invocation and log it to a file", :listing => "trace") do |bp, filename|
run "breakpoint #{bp} if (write_backtrace(%{#{bp}}, caller, %{#{filename}}); false)"
run "continue"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment