egg-audit-mq-log
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

egg-audit-log

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Audit log plugin for egg.js.

Install

$ npm i egg-audit-log --save

Configuration

Change {app_root}/config/plugin.js to enable egg-audit-log plugin:

exports.auditLog = {
  enable: true,
  package: 'egg-audit-log',
};

Usage

Config

exports.auditLog = {
  model: {
    name: 'audit_log',
    expansion: {},
    func: (ctx) => ({}),
  },
  mongoose: {
    url: '',
    options: {},
  },
};
Field Type Remark
model Object Config model for audit-log
model.name String Name for audit-log model
model.expansion Object Expansion for audit-log model
model.func Function Return data to save in audit-log model
mongoose Object Same as egg-audit-log

Example

import { Controller } from 'egg';

class Test extends Controller {
  async create(ctx) {
    await this.app.auditLog.log(ctx, {
      operationType: 'operationType',
      operationContent: 'operationContent',
    });
    return ctx.success();
  }

  async query(ctx) {
    const result = this.app.auditLog.find();
    const total = this.app.auditLog.count();
    return ctx.success({
      data: result,
      total,
    });
  }
}

Middleware Example

export default app => {
  const {
    auditLog: {
      middleware: log,
    },
  } = app;

  app.get('/users', log('log type', 'log content'), 'user.query');
}

License

MIT

Package Sidebar

Install

npm i egg-audit-mq-log

Weekly Downloads

2

Version

1.0.4

License

MIT

Unpacked Size

8.46 kB

Total Files

9

Last publish

Collaborators

  • ewinds