JSON Loggly integration

npm install json-loggly
15 downloads in the last month

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 (req, res) {
  // Do your stuff here

  req.loggly.logBody(input);  // if PUT or POST request with a json body, log it
  res.loggly.logBody(result); // if response contains json body, log it

  .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");



npm loves you