Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix double logging issue properly

  • Loading branch information...
commit 426122e5cc9991573ff62cefb5f5a90b263cc9ef 1 parent a2c67e4
@rkh rkh authored
Showing with 18 additions and 4 deletions.
  1. +18 −4 lib/sinatra/base.rb
View
22 lib/sinatra/base.rb
@@ -87,6 +87,22 @@ def finish
end
end
+ # Behaves exactly like Rack::CommonLogger with the notable exception that it does nothing,
+ # if another CommonLogger is already in the middleware chane.
+ class CommonLogger < Rack::CommonLogger
+ def call(env)
+ env['sinatra.commonlogger'] ? @app.call(env) : super
+ end
+
+ superclass.class_eval do
+ alias call_without_check call unless method_defined? :call_without_check
+ def call(env)
+ env['sinatra.commonlogger'] = true
+ call_without_check(env)
+ end
+ end
+ end
+
class NotFound < NameError #:nodoc:
def http_status; 404 end
end
@@ -1399,8 +1415,7 @@ def setup_null_logger(builder)
end
def setup_common_logger(builder)
- return if defined? WEBrick and ["development", "deployment", nil].include? ENV["RACK_ENV"]
@happy15
happy15 added a note

Does this mean that in development or deployment or nil environment, there is no commonlogger ?

@rkh Owner
rkh added a note

This line has been removed. The assumption was it doesn't, because Rack used to set it up for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
- builder.use Rack::CommonLogger
+ builder.use Sinatra::CommonLogger
end
def setup_custom_logger(builder)
@@ -1432,8 +1447,7 @@ def detect_rack_handler
servers.each do |server_name|
begin
return Rack::Handler.get(server_name.to_s)
- rescue LoadError
- rescue NameError
+ rescue LoadError, NameError
end
end
fail "Server handler (#{servers.join(',')}) not found."

0 comments on commit 426122e

Please sign in to comment.
Something went wrong with that request. Please try again.