0

rack-cache gem relies on @env['rack.errors'] setting to log error messages:

    78:       # write log message to rack.errors
    79:       if verbose?
    80:         binding.pry
    81:         message = "cache: [%s %s] %s\n" %
    82:           [@request.request_method, @request.fullpath, trace]
 => 83:         @env['rack.errors'].write(message)
    84:       end

It is currently set to @env['rack.errors'] #⇒ #<IO:<STDERR>>.

I need to change it to use Rails.logger. The obvious opportunity is to hack into rack-cache initializer RAILS_CACHE.logger = .... I wonder whether there is a common way to access rack environment from Rails, like (pseudocode):

Rails.RACK_ENV['rack.errors'] = Rails.logger
Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160

1 Answers1

1

The Rack environment is only accessible within the context of a request, hence in a controller or view.

To access the environment you can use

request.env['whatever']

Be careful when you modify the Rack environment as other pieces of the Rails stack may rely on it.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
  • I expected there is kinda default settings. Of course, I was able to attach my own middleware to hack into environment, but it sounds both hacky and overengineered to me. Accessing it in controller makes absolutely no sense to me, since I am to override default logging; at this stage there is no controller yet. – Aleksei Matiushkin Jul 08 '15 at 13:14