Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Use rack.logger if it's avaiable #58

Merged
merged 1 commit into from

2 participants

Santiago Pastorino Ryan Tomayko
Santiago Pastorino

Related to this rails/rails#5245

Ryan Tomayko
Owner

Yep. Been meaning to look into this since rack.logger was added. Patch looks great. Merging.

This should go out pretty quickly. I have a feeling we're going to need another release to fix fallout from #52 and the 1.2 release.

Ryan Tomayko rtomayko merged commit 06d089a into from
Santiago Pastorino

@rtomayko ok cool, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 3, 2012
  1. Santiago Pastorino
This page is out of date. Refresh to see the latest.
Showing with 30 additions and 2 deletions.
  1. +15 −2 lib/rack/cache/context.rb
  2. +15 −0 test/context_test.rb
17 lib/rack/cache/context.rb
View
@@ -79,7 +79,7 @@ def call!(env)
if verbose?
message = "cache: [%s %s] %s\n" %
[@request.request_method, @request.fullpath, trace]
- @env['rack.errors'].write(message)
+ log_info(message)
end
# tidy up response a bit
@@ -280,7 +280,20 @@ def strip_ignore_headers(response)
end
def log_error(exception)
- @env['rack.errors'].write("cache error: #{exception.message}\n#{exception.backtrace.join("\n")}\n")
+ message = "cache error: #{exception.message}\n#{exception.backtrace.join("\n")}\n"
+ log(:error, message)
+ end
+
+ def log_info(message)
+ log(:info, message)
+ end
+
+ def log(level, message)
+ if @env['rack.logger']
+ @env['rack.logger'].send(level, message)
+ else
+ @env['rack.errors'].write(message)
+ end
end
end
end
15 test/context_test.rb
View
@@ -913,4 +913,19 @@
response.body.should.equal 'Hello World'
cache.trace.should.include :pass
end
+
+ it 'logs to rack.logger if available' do
+ logger = Class.new do
+ attr_reader :logged_level
+
+ def info(message)
+ @logged_level = "info"
+ end
+ end.new
+
+ respond_with 200
+ get '/', 'rack.logger' => logger
+ response.should.be.ok
+ logger.logged_level.should.equal "info"
+ end
end
Something went wrong with that request. Please try again.