diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-08-19 00:18:26 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-08-19 00:18:26 -0500 |
commit | e9ae2b2f4cae3e9ba4fc8ce91de951d18879af8b (patch) | |
tree | 527dd06fed61304471719a0319280143f0aa1620 /railties | |
parent | 96ab01e8f2b5a4475453acf60f9cf9bd8cd98483 (diff) | |
download | rails-e9ae2b2f4cae3e9ba4fc8ce91de951d18879af8b.tar.gz rails-e9ae2b2f4cae3e9ba4fc8ce91de951d18879af8b.tar.bz2 rails-e9ae2b2f4cae3e9ba4fc8ce91de951d18879af8b.zip |
Added rack logger middleware that tails the environment log
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/rack.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/rack/logger.rb | 28 |
2 files changed, 29 insertions, 0 deletions
diff --git a/railties/lib/rails/rack.rb b/railties/lib/rails/rack.rb index abcd0741bf..b4f32c2d95 100644 --- a/railties/lib/rails/rack.rb +++ b/railties/lib/rails/rack.rb @@ -1,5 +1,6 @@ module Rails module Rack + autoload :Logger, "rails/rack/logger" autoload :Static, "rails/rack/static" end end 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 |