egg-audit-log
v1.1.2
Published
audit log plugin for egg.js
Downloads
7
Maintainers
Readme
egg-audit-log
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');
}