# sails-persistence-logger

> Automatically log all Sails model persistence events

Latest version **0.2.1** (published 2017-12-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install sails-persistence-logger
pnpm add sails-persistence-logger
yarn add sails-persistence-logger
bun add sails-persistence-logger
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2017-12-09 |
| First published | 2017-03-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | TheConnMan |
| Maintainers | theconnman |
| Keywords | Sails, sails, persistence, log, logger |

## Links

- npm: https://www.npmjs.com/package/sails-persistence-logger
- Repository: https://github.com/theconnman/sails-persistence-logger
- Homepage: https://github.com/theconnman/sails-persistence-logger#readme
- Issues: https://github.com/theconnman/sails-persistence-logger/issues
- npm.io page: https://npm.io/package/sails-persistence-logger

## Dependencies (3)

- [extend](https://npm.io/package/extend.md) ^3.0.1
- [log4js](https://npm.io/package/log4js.md) ^1.1.1
- [source-map-support](https://npm.io/package/source-map-support.md) ^0.5.0

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 0.2.1 (latest) — 2017-12-09
- 0.2.0 — 2017-06-04
- 0.1.0 — 2017-03-19

## README

# Sails Persistence Logger

[![NPM](https://nodei.co/npm/sails-persistence-logger.png)](https://nodei.co/npm/sails-persistence-logger/)

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:

```javascript
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']
    }
    ```

---
_Source: https://npm.io/package/sails-persistence-logger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
