aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/rack/logger.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-08-19 00:18:26 -0500
committerJoshua Peek <josh@joshpeek.com>2008-08-19 00:18:26 -0500
commite9ae2b2f4cae3e9ba4fc8ce91de951d18879af8b (patch)
tree527dd06fed61304471719a0319280143f0aa1620 /railties/lib/rails/rack/logger.rb
parent96ab01e8f2b5a4475453acf60f9cf9bd8cd98483 (diff)
downloadrails-e9ae2b2f4cae3e9ba4fc8ce91de951d18879af8b.tar.gz
rails-e9ae2b2f4cae3e9ba4fc8ce91de951d18879af8b.tar.bz2
rails-e9ae2b2f4cae3e9ba4fc8ce91de951d18879af8b.zip
Added rack logger middleware that tails the environment log
Diffstat (limited to 'railties/lib/rails/rack/logger.rb')
-rw-r--r--railties/lib/rails/rack/logger.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb
new file mode 100644
index 0000000000..89d02e45a9
--- /dev/null
+++ b/railties/lib/rails/rack/logger.rb
@@ -0,0 +1,28 @@
+module Rails
+ module Rack
+ class Logger
+ EnvironmentLog = "#{File.expand_path(Rails.root)}/log/#{Rails.env}.log"
+
+ def initialize(app, log = nil)
+ @app = app
+ @path = Pathname.new(log || EnvironmentLog).cleanpath
+ @cursor = ::File.size(@path)
+ @last_checked = Time.now
+ end
+
+ def call(env)
+ response = @app.call(env)
+ ::File.open(@path, 'r') do |f|
+ f.seek @cursor
+ if f.mtime > @last_checked
+ contents = f.read
+ @last_checked = f.mtime
+ @cursor += contents.length
+ print contents
+ end
+ end
+ response
+ end
+ end
+ end
+end