senchalabs/connect — pull request #760 by dylanahsmith (2013-03-11 19:18:54+00:00)
Title: logger: Log even when connections are aborted.

## Problem

As issue #321 reported, aborted requests haven't been logged by connect's logger middleware. That issue was closed by the addition of immediate logging, which is a suitable fix for streaming, but isn't the ideal solution for the case where the client aborts the connection.

## Solution

A listener on the 'close' events can be used to log aborted requests.

Since those aborted requests may not have sent the response code (e.g. by calling `response.writeHead(200)`), the status token will return null if res.headerSent isn't true, rather than the default of 200. This will also fix #378.

I used common function to write the request line to avoid duplicating code with immediate logging. I used the ['finish' event](http://nodejs.org/api/stream.html#stream_event_finish) as proposed in pull #552 so the function could be reused for both the 'close' and 'finish' events.