common-log-string
v0.4.0
Published
dead stupid function to generate a common-log-format-ish string from request & response objects
Downloads
2,510
Maintainers
Readme
common-log-string
Dead stupid function to generate a common-log-format-ish string from request & response objects. Not guaranteed to work with anything other than node-restify.
I wrote this because I wanted something that didn't attempt to write things to a log file and could be plugged into restify as middleware. Sample output:
- - [12/Mar/2015:08:54:46 -0700] "GET /_monitor/ping HTTP/1.1" 200 6 "" "HTTPie/0.8.0"
How to use:
var restify = require('restify');
var logstring = require('common-log-string');
var server = restify.createServer();
server.on('after', request, response, route, error)
{
var output = logstring(request, response);
request.logger.info(output);
});
Order of fields:
- client ip
- client id as per RFC 1413; (unfilled)
- userid as determined by http auth (unfilled by this implementation)
- timestamp
- http request line
- response status code
- length of response body, if available
- referrer string, from request headers
- user agent string, from request headers
- accept string, from request headers
- elapsed time in milliseconds
The second to last is non-standard but useful.
Options
You may optionally pass an options object as the third parameter to the function. One option is currently respected:
ipHeader
: report the client IP from this header instead of the address of the remote socket. Useful if you wish to log X-Forwarded-For IPs instead of the IP of an intermediate proxy.
LICENSE
ISC.