Permalink
Browse files

fix double logging issue properly

  • Loading branch information...
1 parent a2c67e4 commit 426122e5cc9991573ff62cefb5f5a90b263cc9ef @rkh rkh committed Mar 8, 2012
Showing with 18 additions and 4 deletions.
  1. +18 −4 lib/sinatra/base.rb
View
@@ -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 Apr 25, 2012

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

@rkh
rkh Apr 25, 2012 Member

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

- 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.