Created
March 26, 2010 13:15
-
-
Save broofa/344872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add a CLF logger | |
function logCLF(req, res) { | |
var log = [ | |
req.connection.remoteAddress, // client IP | |
'-', // RFC 1413 identity | |
'-', // user id | |
'[' + new Date().toUTCString() + ']', // date | |
'"' + req.method + ' ' + req.url + '"', // request line | |
res.statusCode, // response code | |
'-' // response size (bytes) | |
]; | |
sys.puts(log.join('\t')); | |
} | |
server.addListener('request', function(req, res) { | |
if (res.finished) { | |
logCLF(req, res); | |
} else { | |
res.addListener('close', function(res) { | |
logCLF(req, res); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment