Dead stupid function to generate a common-log-format-ish string from request & response objects.
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
.jshintrc
.travis.yml
LICENSE
README.md
index.js
package.json
test.js

README.md

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.

on npm Tests

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:

  1. client ip
  2. client id as per RFC 1413; (unfilled)
  3. userid as determined by http auth (unfilled by this implementation)
  4. timestamp
  5. http request line
  6. response status code
  7. length of response body, if available
  8. referrer string, from request headers
  9. user agent string, from request headers
  10. accept string, from request headers
  11. 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.