0.2.1 • Published 6 years ago

sails-persistence-logger v0.2.1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Sails Persistence Logger

NPM

Automatically log all Sails model persistence events

Install

npm install --save sails-persistence-logger

Use

To use Sails Persistence Logger out of the box add the logger to config/models.js default persistence hooks so it looks like the following example:

var SailsPersistenceLogger = require('sails-persistence-logger');
var logger = new SailsPersistenceLogger();

module.exports.models = {
  afterCreate: function(record, cb) {
    sailsPersistenceLogger.afterCreate(record, this).then(() => {
      cb();
    });
  },
  afterUpdate: function(record, cb) {
    sailsPersistenceLogger.afterUpdate(record, this).then(() => {
      cb();
    });
  },
  afterDestroy: function(record, cb) {
    sailsPersistenceLogger.afterDestroy(record, this).then(() => {
      cb();
    });
  }
};

And that's it! You'll now have Log4js logging of the form [2017-03-19 15:03:27.608] [INFO] sails-persistence-logger - Created event 42 for all persistence events.

API

require('sails-persistence-logger')(options: Object)

Initializes Sails Persistence Logger with the given options. All options are optional.

  • options.logger: Log4js compatible logger which Sails Persistence Logger will use
  • options.level: (default: info) Log4js logging level ('debug', 'info', 'warn', 'error')
  • options.exclude: Object used to exclude full models or specific methods on a model from logging

    • Example option excluding all video model logging and updates on review model logging:

      {
        video: true,
        review: ['UPDATE'] // Allowed options are ['CREATE', 'UPDATE', 'DESTROY']
      }