Class: Logput::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/logput/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Middleware

Returns a new instance of Middleware.



3
4
5
6
7
# File 'lib/logput/middleware.rb', line 3

def initialize(app, options = {})
  @app = app
  @path_to_log_file = options[:path_to_log_file]
  @lines_to_read = options[:lines_to_read] || 500
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/logput/middleware.rb', line 9

def call(env)
  @path_to_log_file ||= default_path_to_log_file(env)

  raise 'Log file does not exist' unless File.exists? @path_to_log_file

  if env['PATH_INFO'] == '/logput'
    out = `tail -n #{@lines_to_read} #{@path_to_log_file}`
    [200, {"Content-Type" => "text/html"}, ["<pre>", out, "</pre>"]]
  else
    @app.call(env)
  end
end