summary refs log tree commit
path: root/lib/rack/commonlogger.rb
diff options
context:
space:
mode:
authorUriel Katz <uriel.katz@gmail.com>2013-08-12 11:01:43 +0300
committerUriel Katz <uriel.katz@gmail.com>2013-12-07 14:06:50 +0200
commite3772a5870c32b5f9951a8356298200ce868bf23 (patch)
tree3ae2e349337a5d21e77af7f105b0442b240f9aa5 /lib/rack/commonlogger.rb
parent734a00c5f4bb46e9a5e6e2677d89a2f285dcc185 (diff)
downloadrack-e3772a5870c32b5f9951a8356298200ce868bf23.tar.gz
Possible fix for #412
Diffstat (limited to 'lib/rack/commonlogger.rb')
-rw-r--r--lib/rack/commonlogger.rb7
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"),