提交 e9ae2b2f 编写于 作者: J Joshua Peek

Added rack logger middleware that tails the environment log

上级 96ab01e8
module Rails
module Rack
autoload :Logger, "rails/rack/logger"
autoload :Static, "rails/rack/static"
end
end
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册