Sha256: 08e45fa18698263ffda34fb41d2d6a9fcf2faee832d45d23e4b21986c7e37296

Contents?: true

Size: 841 Bytes

Versions: 49

Compression:

Stored size: 841 Bytes

Contents

require 'active_support/deprecation'

module Rails
  module Rack
    class LogTailer
      def initialize(app, log = nil)
        ActiveSupport::Deprecation.warn('LogTailer is deprecated and will be removed on Rails 5.')

        @app = app

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

        @cursor = @file = nil
        if ::File.exist?(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

49 entries across 48 versions & 8 rubygems

Version Path
railties-4.2.11.3 lib/rails/rack/log_tailer.rb
railties-4.2.11.2 lib/rails/rack/log_tailer.rb
railties-4.2.11.1 lib/rails/rack/log_tailer.rb
railties-4.2.11 lib/rails/rack/log_tailer.rb
railties-4.2.10 lib/rails/rack/log_tailer.rb
railties-4.2.10.rc1 lib/rails/rack/log_tailer.rb
railties-4.2.9 lib/rails/rack/log_tailer.rb
railties-4.2.9.rc2 lib/rails/rack/log_tailer.rb
railties-4.2.9.rc1 lib/rails/rack/log_tailer.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/railties-4.2.8/lib/rails/rack/log_tailer.rb
railties-4.2.8 lib/rails/rack/log_tailer.rb
railties-4.2.8.rc1 lib/rails/rack/log_tailer.rb
railties-4.2.7.1 lib/rails/rack/log_tailer.rb
railties-4.2.7 lib/rails/rack/log_tailer.rb
railties-4.2.7.rc1 lib/rails/rack/log_tailer.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-4.2.6/lib/rails/rack/log_tailer.rb
railties-4.2.6 lib/rails/rack/log_tailer.rb
railties-4.2.6.rc1 lib/rails/rack/log_tailer.rb
railties-4.2.5.2 lib/rails/rack/log_tailer.rb
activejob-lock-0.0.2 rails/railties/lib/rails/rack/log_tailer.rb