Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if logger responds to write #1081

Merged
merged 1 commit into from Sep 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/puma/commonlogger.rb
Expand Up @@ -49,8 +49,7 @@ def call(env)
def log_hijacking(env, status, header, began_at)
now = Time.now

logger = @logger || env['rack.errors']
logger.write HIJACK_FORMAT % [
msg = HIJACK_FORMAT % [
env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-",
env["REMOTE_USER"] || "-",
now.strftime("%d/%b/%Y %H:%M:%S"),
Expand All @@ -59,6 +58,8 @@ def log_hijacking(env, status, header, began_at)
env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"],
env["HTTP_VERSION"],
now - began_at ]

write(msg)
end

PATH_INFO = 'PATH_INFO'.freeze
Expand Down Expand Up @@ -88,7 +89,12 @@ def log(env, status, header, began_at)
length,
now - began_at ]

write(msg)
end

def write(msg)
logger = @logger || env['rack.errors']

# Standard library logger doesn't support write but it supports << which actually
# calls to write on the log device without formatting
if logger.respond_to?(:write)
Expand Down