Class: RightSupport::Rack::LogSetter Deprecated

Inherits:
Object
  • Object
show all
Defined in:
lib/right_support/rack/log_setter.rb

Overview

Deprecated.

this class will be removed in RightSupport 3.0, please do not use it

A Rack middleware that logs information about every HTTP request received and every exception raised while processing a request.

The middleware can be configured to use its own logger, but defaults to using env for logging if it is present. If ‘rack.logger’ is not set, this middleware will set it before calling the next middleware. Therefore, RequestLogger can be used standalone to fulfill all logging needs, or combined with Rack::Logger or another middleware that provides logging services.

Instance Method Summary collapse

Constructor Details

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

Initialize an instance of the middleware. For backward compatibility, the order of the logger and level parameters can be switched.

Parameters

app(Object)

the inner application or middleware layer; must respond to #call

logger(Logger)

(optional) the Logger object to use, defaults to a STDERR logger

level(Integer)

(optional) a Logger level-constant (INFO, ERROR) to set the logger to



45
46
47
48
49
# File 'lib/right_support/rack/log_setter.rb', line 45

def initialize(app, options={})
  @app    = app
  @logger = options[:logger]
  warn "#{self.class.name} is deprecated and will be removed in 3.0, please refrain from using it"
end

Instance Method Details

#call(env) ⇒ Object

Add a logger to the Rack environment and call the next middleware.

Parameters

env(Hash)

the Rack environment

Return

always returns whatever value is returned by the next layer of middleware



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/right_support/rack/log_setter.rb', line 58

def call(env)
  if @logger
    logger = @logger
  elsif env['rack.logger']
    logger = env['rack.logger']
  end

  env['rack.logger'] ||= logger

  return @app.call(env)
end