-
-
Save atomical/8692640 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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