Documentation Menu

Logging to databases and services using Winston transports

By default, jsnlog.js on the server sends all log messages to the console (on the client it sends log messages to the server via AJAX). However, you might want to log to a database, such as MongoDB, or a logging service, such as Loggly.

To make this easy, jsnlog.js lets you plug in Winston transports. There are transports not only for MongoDB and Loggly, but also SimpleDB, email, Cassandra and lots more.

The code below shows how to plug in the Winston transport for MongoDB. Using other Winston transports goes along the same lines.

npm install winston
npm install winston-mongodb
var JL = require('jsnlog').JL;
var winston = require('winston');
// The JSON object passed to the MongoDB function below contains options for the // MongoDB transport. See the documentation for your chosen transport for its options. // The options given here are just examples. var mongo_appender = new winston.transports.MongoDB({ db: 'logs', collection: 'log' }); JL().setOptions({ "appenders": [mongo_appender] });