Skip to content

Instantly share code, notes, and snippets.

@broofa
Created March 26, 2010 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save broofa/344872 to your computer and use it in GitHub Desktop.
Save broofa/344872 to your computer and use it in GitHub Desktop.
// 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