Audit log plugin for egg.js.
$ npm i egg-audit-log --save
Change {app_root}/config/plugin.js
to enable egg-audit-log
plugin:
exports.auditLog = {
enable: true,
package: 'egg-audit-log',
};
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 |
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,
});
}
}
export default app => {
const {
auditLog: {
middleware: log,
},
} = app;
app.get('/users', log('log type', 'log content'), 'user.query');
}