loggly logging middleware for connect


A loggly logger middleware for connect.

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
var loggly = require('loggly').createClient(myLogglyConfig)
  , connectLoggly = require('connect-loggly');
// If you are using express (otherwise just say `connect`) 

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.token('user-id', function (req) {
  return req.user && req.user._id;
// A custom field from the session 
connectLoggly.token('session', function (reqresfield) {
  return req.session && req.session[field];

And now we can change what the logged JSON is:

var logglyRequestTokens = {
  // Default fields 
  url: true,
  method: true,
  'response-time': true,
  date: true,
  status: true,
  'user-agent': true,
  'http-version': true,
  // Custom headers 
  'req': 'Accepts',
  'res': 'Location',
  // Custom tokens (see below) 
  'user-id': true,
  'session': 'someFieldInTheSession',
  // Static information 
  'server-instance': 'abc123'
express.use(connectLoggly(logglyClient, logglyRequestTokens));

Note: Just be sure to add all custom tokens BEFORE setting up the middleware.

  • url (default) - URL
  • method (default) - HTTP Method
  • response-time (default) - Response time
  • date (default) - UTC time
  • status (default) - HTTP status
  • referrer - Request header referrer
  • http-version (default) - HTTP version
  • user-agent (default) - Request header User Agent
  • req (accepts field) - Arbitrary request header
  • res (accepts field) - Arbitrary response header

See LICENSE file