2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/response_logger.rb', line 2
def self.included(base)
base.class_eval do
alias_method :original_request, :request
def request(req, body = nil, &block)
if @already_called
res = original_request(req, body, &block)
else
@already_called = true
file = Time.now.strftime("%H%M%S")
file_path = File.join(RAILS_ROOT, "log", Date.today.strftime("%Y/%m/%d"), @port.to_s, @address, req.path.sub(/^\//, ''))
FileUtils.mkdir_p(file_path)
res = original_request(req, body, &block)
File.open(File.join(file_path, file), "w+") do |f|
f.write(res.body)
end
end
@already_called = false
res
end
end
end
|