Class: Streamlog::LogsController

Inherits:
ApplicationController show all
Includes:
ActionController::Live
Defined in:
app/controllers/streamlog/logs_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



8
9
# File 'app/controllers/streamlog/logs_controller.rb', line 8

def index
end

#streamObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/streamlog/logs_controller.rb', line 11

def stream
  response.headers['Content-Type'] = 'text/event-stream'

  sse = Streamlog::SSE.new(response.stream)
  colorizer = Streamlog::LogColorize.new

  begin
    File::Tail::Logfile.tail(Rails.root.join('log', Rails.env+'.log').to_s, backward: 1) do |line|
      sse.write colorizer.colorize_line line
    end
  rescue IOError
    # When the client disconnects, we'll get an IOError on write
  ensure
    sse.close
  end
end