This is a small piece of middleware to help you log important information about a request to loggly using their JSON api.
npm install connect-loggly --save
You must construct the loggly client in JSON mode with
json: true in the loggly config.
var logglyClient = // Make sure json: true in config!connectLoggly = ;// If you are using express (otherwise just say `connect`)express
You can change what the default message looks like. Like
connect.logger(), this middleware deals in tokens which can be customly added using the
token function. First, lets see how we can add new tokens:
// Lets add some tokens!// A user-id from the req.user object (this would work for mongoose/passport)connectLoggly;// A custom field from the sessionconnectLoggly;
And now we can change what the logged JSON is. We pass in an token-list, an object of keys which are token names or static fields. The token-list fields' values are replaced with token values from the request and response and sent as a JSON object. Some tokens (
res in the default set) accept parameters as a field, these are the token-list values.
var logglyRequestTokens =// Default fieldsurl: truemethod: true'response-time': truedate: truestatus: true'user-agent': true'http-version': true// Custom headers'req': 'Accepts''res': 'Location'// Custom tokens (see above)'user-id': true'session': 'someFieldInTheSession'// Static information'server-instance': 'abc123';express;
Note: Just be sure to add all custom tokens BEFORE setting up the middleware.
See LICENSE file