json-loggly

JSON Loggly integration

Usage no npm install needed!

<script type="module">
  import jsonLoggly from 'https://cdn.skypack.dev/json-loggly';
</script>

README

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.

Usage

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) {
  var result = {}; // the json response object send back to the client

  // Do your stuff here

  res.loggly.setResponseObj(result);
  res.end(JSON.stringify(result));
};

connect()
  .use(loggly.middleware()) // inject json-loggly middleware early
  .use(app)                 // Your normal app request handling
  .listen(8080);

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
loggly.inf({
  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");

License

MIT