diff --git a/lib/log_overrider.rb b/lib/log_overrider.rb index 85bb64d6b..fcc610c70 100644 --- a/lib/log_overrider.rb +++ b/lib/log_overrider.rb @@ -3,7 +3,8 @@ class ActionView::LogSubscriber message = "event=render " message << "template=#{from_rails_root(event.payload[:identifier])} " message << "layout=#{from_rails_root(event.payload[:layout])} " if event.payload[:layout] - message << "ms=#{("%.1f" % event.duration)}" + message << "ms=#{("%.1f" % event.duration)} " + #message << "r_id=#{event.transaction_id} " Rails.logger.info(message) end alias :render_partial :render_template @@ -24,7 +25,8 @@ class ActionController::LogSubscriber log_string << "controller=#{payload[:controller]} action=#{payload[:action]} format=#{payload[:formats].first.to_s.upcase} " log_string << "ms=#{"%.0f" % event.duration} " log_string << "params='#{params.inspect}' " unless params.empty? - log_string << "additions='#{additions.join(" | ")}'" unless additions.blank? + #log_string << "additions='#{additions.join(" | ")}' " unless additions.blank? + log_string << "r_id=#{event.transaction_id} " Rails.logger.info(log_string) end diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index 806bc0a72..2093119c5 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -27,11 +27,48 @@ describe HomeController do end #This describe should apply to any controller class. HomeController is just the simplest. - describe 'logging' do + describe 'log overriding in lib/log_overrider' do before do - logger = FakeLogger.new Rails.stub(:logger).and_return(FakeLogger.new) end + context 'cross-stage' do + before do + get :show + @lines = Rails.logger.infos + @id = @lines.first.match(/r_id=(\w+)\s/).captures.first + end + 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 + @lines.each do |line| + line.match(/r_id=(\w+)\s/).captures.first.should == @id + end + end + it 'logs different ids in different requests' do + pending "This might require patching Rails" + get :show + old_lines = Rails.logger.infos.select do |line| + line.match(/r_id=(\w+)\s/).captures.first == @id + end + old_lines.length.should == Rails.logger.infos.length/2 + end + end + context 'rendering' do + before do + get :show, :lasers => 'green' + @lines = Rails.logger.infos.select{|l| l.include?("event=render")} + end + it 'logs all renders' do + @lines.length.should == 2 + end + it 'logs layouts' do + pending 'where is the template=home/show line?' + home_line = @lines.detect{|t| + t.include?("template=home/show.html.haml")} + home_line.should match /layout=layouts\/application/ + end + + end context 'completion' do context 'ok' do before do