1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 'use strict';
- /**
- * 自动记录日志
- *
- * @author CaiAoLin
- * @date 2017/10/30
- * @version
- */
- module.exports = options => {
- return function* autoLogger(next) {
- // 记录业务日志
- function getBussinessLogger(ctx) {
- if (ctx.url.match(/ledger/)) {
- return ctx.getLogger('ledger');
- } else if (ctx.url.match(/stage/)) {
- return ctx.getLogger('stage');
- }
- return ctx.getLogger('mixed');
- }
- if (this.session.sessionUser) {
- const bLogger = getBussinessLogger(this);
- const logData = {
- method: this.method,
- user: this.session.sessionUser,
- project: this.session.sessionProject,
- data: this.body,
- };
- bLogger.info(JSON.stringify(logData));
- }
- // 自动记录log的action
- // const autoLogAction = ['save', 'delete'];
- // if (this.actionName !== undefined && autoLogAction.indexOf(this.actionName) >= 0) {
- // // 操作数据的id
- // const idReg = /\/(\d+)/;
- // const paramInfo = this.request.originalUrl.match(idReg);
- // let targetId = paramInfo[1] !== undefined ? paramInfo[1] : -1;
- // targetId = parseInt(targetId);
- //
- // const logData = {
- // controller: this.controllerName,
- // action: this.actionName,
- // operation: this.currentName === undefined ? '保存数据' : this.currentName,
- // target_id: targetId,
- // };
- // yield this.service.log.addLog(logData);
- // }
- yield next;
- };
- };
|