Skip to content

Instantly share code, notes, and snippets.

@atomical
Forked from ahoward/net-http-debug.rb
Last active August 29, 2015 13:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atomical/8692640 to your computer and use it in GitHub Desktop.
Save atomical/8692640 to your computer and use it in GitHub Desktop.
require 'net/http'
# $ cat http_requests.log | grep "GET /" | wc -l
class BacktraceLogger
def initialize
end
def << ( s )
open
@@file.write s
@@file.write backtrace
end
private
def open
@@file ||= File.open('http_requests.log','a+')
open_bool = @@file.lstat rescue nil
if ! open_bool
@@file = File.open('http_requests.log','a+')
end
end
def backtrace
begin
raise 'backtrace'
rescue Exception => e
end
e.backtrace[8..-1].join("\n")
end
end
if Rails.env.development?
Net::HTTP.module_eval do
alias_method '__initialize__', 'initialize'
def initialize(*args,&block)
__initialize__(*args, &block)
ensure
# File.open('http_requests.log','a+') #$stderr ### if ENV['HTTP_DEBUG']
@debug_output = BacktraceLogger.new
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment