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

1.1.2 • 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',
    expand: {},
  },
  mongoose: {
    url: '',
    options: {},
  },
};
Field Type Remark
model Object Config model for audit-log
model.name String Name for audit-log model
model.expand Object Expansion for audit-log model
mongoose Object Same as egg-mongoose

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.model.find({});
    const total = this.app.auditLog.model.countDocuments();
    return ctx.success({
      data: result,
      total,
    });
  }
}

Middleware Example

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

  app.get('/users', log('log type', 'log content', (ctx) => { operator: 'admin'}), 'user.query');
}

License

MIT

Package Sidebar

Install

npm i egg-audit-log

Weekly Downloads

5

Version

1.1.2

License

MIT

Unpacked Size

9.07 kB

Total Files

10

Last publish

Collaborators

  • mintsweet