Sha256: 952692f1af1d5cd8f762a1ca2efeffeaf5c4e3679f7815539bf420f4aac45327

Contents?: true

Size: 704 Bytes

Versions: 125

Compression:

Stored size: 704 Bytes

Contents

module Rails
  module Rack
    class LogTailer
      def initialize(app, log = nil)
        @app = app

        path = Pathname.new(log || "#{::File.expand_path(Rails.root)}/log/#{Rails.env}.log").cleanpath

        @cursor = @file = nil
        if ::File.exists?(path)
          @cursor = ::File.size(path)
          @file = ::File.open(path, 'r')
        end
      end

      def call(env)
        response = @app.call(env)
        tail!
        response
      end

      def tail!
        return unless @cursor
        @file.seek @cursor

        unless @file.eof?
          contents = @file.read
          @cursor = @file.tell
          $stdout.print contents
        end
      end
    end
  end
end

Version data entries

125 entries across 102 versions & 19 rubygems

Version Path
railties-3.2.22.5 lib/rails/rack/log_tailer.rb
railties-3.2.22.4 lib/rails/rack/log_tailer.rb
railties-3.2.22.3 lib/rails/rack/log_tailer.rb
railties-3.2.22.2 lib/rails/rack/log_tailer.rb
railties-3.2.22.1 lib/rails/rack/log_tailer.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/rack/log_tailer.rb
railties-3.2.22 lib/rails/rack/log_tailer.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/railties-3.2.12/lib/rails/rack/log_tailer.rb
railties-3.2.21 lib/rails/rack/log_tailer.rb
railties-3.2.20 lib/rails/rack/log_tailer.rb
railties-3.2.19 lib/rails/rack/log_tailer.rb
railties-3.2.18 lib/rails/rack/log_tailer.rb
railties-3.2.17 lib/rails/rack/log_tailer.rb
railties-4.0.3 lib/rails/rack/log_tailer.rb
railties-4.0.2 lib/rails/rack/log_tailer.rb
railties-3.2.16 lib/rails/rack/log_tailer.rb
railties-4.0.1 lib/rails/rack/log_tailer.rb
railties-4.0.1.rc4 lib/rails/rack/log_tailer.rb
railties-4.0.1.rc3 lib/rails/rack/log_tailer.rb
railties-4.0.1.rc2 lib/rails/rack/log_tailer.rb