aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/commands/servers/base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/commands/servers/base.rb')
-rw-r--r--railties/lib/commands/servers/base.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/railties/lib/commands/servers/base.rb b/railties/lib/commands/servers/base.rb
new file mode 100644
index 0000000000..25b2935524
--- /dev/null
+++ b/railties/lib/commands/servers/base.rb
@@ -0,0 +1,19 @@
+def tail(log_file)
+ cursor = File.size(log_file)
+ last_checked = Time.now
+ tail_thread = Thread.new do
+ File.open(log_file, 'r') do |f|
+ loop do
+ f.seek cursor
+ if f.mtime > last_checked
+ last_checked = f.mtime
+ contents = f.read
+ cursor += contents.length
+ print contents
+ end
+ sleep 1
+ end
+ end
+ end
+ tail_thread
+end