提交 6703f909 编写于 作者: J Jeremy Kemper

Cheaper log tail time comparison

上级 a9fde9a2
...@@ -7,16 +7,16 @@ def initialize(app, log = nil) ...@@ -7,16 +7,16 @@ def initialize(app, log = nil)
@app = app @app = app
@path = Pathname.new(log || EnvironmentLog).cleanpath @path = Pathname.new(log || EnvironmentLog).cleanpath
@cursor = ::File.size(@path) @cursor = ::File.size(@path)
@last_checked = Time.now @last_checked = Time.now.to_f
end end
def call(env) def call(env)
response = @app.call(env) response = @app.call(env)
::File.open(@path, 'r') do |f| ::File.open(@path, 'r') do |f|
f.seek @cursor f.seek @cursor
if f.mtime > @last_checked if f.mtime.to_f > @last_checked
contents = f.read contents = f.read
@last_checked = f.mtime @last_checked = f.mtime.to_f
@cursor += contents.length @cursor += contents.length
print contents print contents
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册