Skip to content

Instantly share code, notes, and snippets.

@mrajagopal
Created October 29, 2014 03:43
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 mrajagopal/cdc159909cfab256a5fe to your computer and use it in GitHub Desktop.
Save mrajagopal/cdc159909cfab256a5fe to your computer and use it in GitHub Desktop.
LineRate snippet: Request Logging with Bunyan
"use strict";
var vsm = require('lrs/virtualServerModule');
var bunyan = require('bunyan');
// Function to return required fields from the request object
function reqSerializer(req) {
return {
method: req.method,
url: req.url,
headers: req.headers.host
}
}
var log = bunyan.createLogger({name: "LineRate proxy", serializers: {req: reqSerializer}});
// Handler for client requests
function onClientReq(servReq, servResp, next) {
// Access the bunyan logger to output specific fields of the server request object
log.info(reqSerializer(servReq));
next();
}
vsm.on('exist', 'yourVirtualServerName', function (vs) {
vs.on('request', onClientReq);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment