From 418c872c95f237ea2a27a72676cb277affa9aa22 Mon Sep 17 00:00:00 2001 From: Curtis Cablegram Date: Wed, 28 Jul 2010 19:34:04 -0500 Subject: [PATCH 1/2] Change log-tailer to properly track multi-byte characters. When end-of-line is represented within a file as "\r\n", it is represented in memory as a single "\n". This patch eliminates the discrepancy between size on disk and size in memory. --- railties/lib/rails/rack/log_tailer.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/railties/lib/rails/rack/log_tailer.rb b/railties/lib/rails/rack/log_tailer.rb index 3fa4515..2ca6b5f 100644 --- a/railties/lib/rails/rack/log_tailer.rb +++ b/railties/lib/rails/rack/log_tailer.rb @@ -24,7 +24,7 @@ module Rails if mod > @last_checked contents = @file.read @last_checked = mod - @cursor += contents.size + @cursor = @file.tell $stdout.print contents end end -- 1.6.5.1.1367.gcd48 From 51afdc706ac70af76d3a47bd2df2029ca102be86 Mon Sep 17 00:00:00 2001 From: Curtis Cablegram Date: Wed, 28 Jul 2010 19:47:53 -0500 Subject: [PATCH 2/2] Refactor log-tailer to depend on File#eof? rather than File#mtime Eliminate 1 instance variable and 1 local variable. --- railties/lib/rails/rack/log_tailer.rb | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-) diff --git a/railties/lib/rails/rack/log_tailer.rb b/railties/lib/rails/rack/log_tailer.rb index 2ca6b5f..011ac6c 100644 --- a/railties/lib/rails/rack/log_tailer.rb +++ b/railties/lib/rails/rack/log_tailer.rb @@ -6,7 +6,6 @@ module Rails path = Pathname.new(log || "#{File.expand_path(Rails.root)}/log/#{Rails.env}.log").cleanpath @cursor = ::File.size(path) - @last_checked = Time.now.to_f @file = ::File.open(path, 'r') end @@ -20,10 +19,8 @@ module Rails def tail! @file.seek @cursor - mod = @file.mtime.to_f - if mod > @last_checked + if !@file.eof? contents = @file.read - @last_checked = mod @cursor = @file.tell $stdout.print contents end -- 1.6.5.1.1367.gcd48