Giter Site home page Giter Site logo

sails-persistence-logger's Introduction

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']
      }
      

sails-persistence-logger's People

Contributors

theconnman avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.