Class: Low::Rack::RackErrors

Inherits:
Object
  • Object
show all
Defined in:
lib/low/rack/rack_errors.rb

Constant Summary collapse

DEFAULT_FS_ENVS =
['development', 'test']

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}) ⇒ RackErrors

Returns a new instance of RackErrors.



7
8
9
10
# File 'lib/low/rack/rack_errors.rb', line 7

def initialize(app, opts = {})
  @app = app
  @fs_envs = opts[:fs_envs] || DEFAULT_FS_ENVS
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
# File 'lib/low/rack/rack_errors.rb', line 12

def call(env)
  env['rack.errors'] ||= io
  @app.call(env)
end

#ioObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/low/rack/rack_errors.rb', line 17

def io
  # If `RACK_ENV` should log to the FS,
  if @fs_envs.include? ENV['RACK_ENV']
    # make sure the log directory exists,
    Dir.mkdir('log') unless Dir.exists?('log')

    # and log to an eponymous file;
    File.open("log/#{ENV['RACK_ENV']}.log", 'a')
  else
    # otherwise, log to STDOUT (Heroku likes it this way).
    STDOUT
  end
end