Override request started log line
This commit is contained in:
parent
d69bca28ef
commit
e86a5563ed
2 changed files with 25 additions and 3 deletions
|
|
@ -31,3 +31,16 @@ class ActionController::LogSubscriber
|
||||||
Rails.logger.info(log_string)
|
Rails.logger.info(log_string)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module Rails
|
||||||
|
module Rack
|
||||||
|
class Logger
|
||||||
|
def before_dispatch(env)
|
||||||
|
request = ActionDispatch::Request.new(env)
|
||||||
|
path = request.fullpath
|
||||||
|
|
||||||
|
Rails.logger.info("event=request_started verb=#{env["REQUEST_METHOD"]} path=#{path} ip=#{request.ip} ")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -33,19 +33,18 @@ describe HomeController do
|
||||||
end
|
end
|
||||||
context 'cross-stage' do
|
context 'cross-stage' do
|
||||||
before do
|
before do
|
||||||
|
pending "This might require patching Rails"
|
||||||
get :show
|
get :show
|
||||||
@lines = Rails.logger.infos
|
@lines = Rails.logger.infos
|
||||||
@id = @lines.first.match(/r_id=(\w+)\s/).captures.first
|
@id = @lines[1].match(/r_id=(\w+)\s/).captures.first
|
||||||
end
|
end
|
||||||
it 'logs a unified id in a request' do
|
it 'logs a unified id in a request' do
|
||||||
pending "This might require patching Rails"
|
|
||||||
id = @lines.first.match(/r_id=(\w+)\s/).captures.first
|
id = @lines.first.match(/r_id=(\w+)\s/).captures.first
|
||||||
@lines.each do |line|
|
@lines.each do |line|
|
||||||
line.match(/r_id=(\w+)\s/).captures.first.should == @id
|
line.match(/r_id=(\w+)\s/).captures.first.should == @id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
it 'logs different ids in different requests' do
|
it 'logs different ids in different requests' do
|
||||||
pending "This might require patching Rails"
|
|
||||||
get :show
|
get :show
|
||||||
old_lines = Rails.logger.infos.select do |line|
|
old_lines = Rails.logger.infos.select do |line|
|
||||||
line.match(/r_id=(\w+)\s/).captures.first == @id
|
line.match(/r_id=(\w+)\s/).captures.first == @id
|
||||||
|
|
@ -53,6 +52,16 @@ describe HomeController do
|
||||||
old_lines.length.should == Rails.logger.infos.length/2
|
old_lines.length.should == Rails.logger.infos.length/2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
context 'starting' do
|
||||||
|
before do
|
||||||
|
pending "This code is never reached in tests, but it seems to work in actual requests"
|
||||||
|
get :show
|
||||||
|
@line = Rails.logger.infos.first
|
||||||
|
end
|
||||||
|
it 'logs it' do
|
||||||
|
@line.should match /event=request_started/
|
||||||
|
end
|
||||||
|
end
|
||||||
context 'rendering' do
|
context 'rendering' do
|
||||||
before do
|
before do
|
||||||
get :show, :lasers => 'green'
|
get :show, :lasers => 'green'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue