JSON Loggly integration

JSON Loggly

A node.js module for Loggly, espcially optimized for node.js API servers that deal in JSON requests and responses and uses connect for middleware management.

When calling res.end(), the json-loggly module will automatically log the request to Loggly and stdout.

json-loggly can also log custom log messages and support 4 different log levels: debug, info, warning and error.

json-loggly is very simple to use. To log requests, simply:

var connect = require('connect');
var loggly = require('json-loggly').init('your-loggly-api-key');
var app = function (reqres) {
  var result = {}; // the json response object send back to the client 
  // Do your stuff here 
  .use(loggly.middleware()) // inject json-loggly middleware early 
  .use(app)                 // Your normal app request handling 

To log a custom log message use the json-loggly methods dbg, inf, war or err:

var loggly = require('json-loggly').init('your-loggly-api-key');
// Provide a custom object to be logged 
  service : 'sendgrid',
  msg     : 'Sending welcome e-mail to newly created user',
  to      : { id: user._id, email: user.email }
// Or just log a string 
loggly.err("Something bad happened");