Class: Low::Rack::LogLevel

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

Constant Summary collapse

DEFAULT_DEFAULT_LEVEL =
Logger::INFO

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of LogLevel.



9
10
11
12
# File 'lib/low/rack/log_level.rb', line 9

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

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
# File 'lib/low/rack/log_level.rb', line 14

def call(env)
  env['low.log_level'] ||= log_level
  @app.call(env)
end

#log_levelObject



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

def log_level
  # If `LOG_LEVEL` is a valid level
  if ['FATAL', 'ERROR', 'WARN', 'INFO', 'DEBUG'].include? ENV['LOG_LEVEL']
    # use it;
    eval "Logger::#{ENV['LOG_LEVEL']}"
  else
    # otherwise, use the default
    @default_level
  end
end