Created
October 29, 2014 03:43
-
-
Save mrajagopal/cdc159909cfab256a5fe to your computer and use it in GitHub Desktop.
LineRate snippet: Request Logging with Bunyan
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
"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