summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-01-27 09:07:58 -0800
committerJeremy Evans <code@jeremyevans.net>2020-01-27 09:14:16 -0800
commite8f2eea34ed9c7257be722988f02cf3893372119 (patch)
tree6525faacde925ebff871b2f6a6ae4f0dcc47ed67
parenta5fc97bdfc3e92dc5539ffd2a19b5adc8f6601a0 (diff)
downloadrack-e8f2eea34ed9c7257be722988f02cf3893372119.tar.gz
Refactor common logger to avoid string allocation
This uses separate placeholders for SCRIPT_NAME and PATH_INFO. Fixes #1070
-rw-r--r--lib/rack/common_logger.rb9
1 files changed, 3 insertions, 6 deletions
diff --git a/lib/rack/common_logger.rb b/lib/rack/common_logger.rb
index 3a062474..de604f5b 100644
--- a/lib/rack/common_logger.rb
+++ b/lib/rack/common_logger.rb
@@ -23,7 +23,7 @@ module Rack
# lilith.local - - [07/Aug/2006 23:58:02 -0400] "GET / HTTP/1.1" 500 -
#
# %{%s - %s [%s] "%s %s%s %s" %d %s\n} %
- FORMAT = %{%s - %s [%s] "%s %s%s %s" %d %s %0.4f\n}
+ FORMAT = %{%s - %s [%s] "%s %s%s%s %s" %d %s %0.4f\n}
def initialize(app, logger = nil)
@app = app
@@ -48,7 +48,8 @@ module Rack
env["REMOTE_USER"] || "-",
Time.now.strftime("%d/%b/%Y:%H:%M:%S %z"),
env[REQUEST_METHOD],
- path(env),
+ env[SCRIPT_NAME],
+ env[PATH_INFO],
env[QUERY_STRING].empty? ? "" : "?#{env[QUERY_STRING]}",
env[SERVER_PROTOCOL],
status.to_s[0..3],
@@ -65,10 +66,6 @@ module Rack
end
end
- def path(env)
- env[SCRIPT_NAME] + env[PATH_INFO]
- end
-
def extract_content_length(headers)
value = headers[CONTENT_LENGTH]
!value || value.to_s == '0' ? '-' : value