diff options
author | Uriel Katz <uriel.katz@gmail.com> | 2013-08-12 11:01:43 +0300 |
---|---|---|
committer | Uriel Katz <uriel.katz@gmail.com> | 2013-12-07 14:06:50 +0200 |
commit | e3772a5870c32b5f9951a8356298200ce868bf23 (patch) | |
tree | 3ae2e349337a5d21e77af7f105b0442b240f9aa5 /lib/rack/commonlogger.rb | |
parent | 734a00c5f4bb46e9a5e6e2677d89a2f285dcc185 (diff) | |
download | rack-e3772a5870c32b5f9951a8356298200ce868bf23.tar.gz |
Possible fix for #412
Diffstat (limited to 'lib/rack/commonlogger.rb')
-rw-r--r-- | lib/rack/commonlogger.rb | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/rack/commonlogger.rb b/lib/rack/commonlogger.rb index 3684a7d1..b83b82d2 100644 --- a/lib/rack/commonlogger.rb +++ b/lib/rack/commonlogger.rb @@ -10,7 +10,7 @@ module Rack # an instance of Rack::NullLogger. # # +logger+ can be any class, including the standard library Logger, and is - # expected to have a +write+ method, which accepts the CommonLogger::FORMAT. + # expected to have either +write+ or +<<+ method, which accepts the CommonLogger::FORMAT. # According to the SPEC, the error stream must also respond to +puts+ # (which takes a single argument that responds to +to_s+), and +flush+ # (which is called without arguments in order to make the error appear for @@ -43,7 +43,10 @@ module Rack length = extract_content_length(header) logger = @logger || env['rack.errors'] - logger.write FORMAT % [ + #Standard library logger doesn't support write but it supports << which actually + #calls to write on the log device without formatting + write = logger.respond_to?(:write) ? logger.method(:write) : logger.method(:<<) + write.call FORMAT % [ env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-", env["REMOTE_USER"] || "-", now.strftime("%d/%b/%Y:%H:%M:%S %z"), |