21 lines
584 B
TypeScript
21 lines
584 B
TypeScript
import { genCode } from "@pubUtils/util";
|
|
|
|
module.exports = () => {
|
|
return async function log(ctx, next) {
|
|
ctx.logcode = genCode(10);
|
|
|
|
ctx.service.utils.log('INFO', `[${ctx.request.url}] [${ctx.logcode}] request: ${JSON.stringify(ctx.request.body)}`)
|
|
|
|
|
|
try{
|
|
await next();
|
|
} catch(e) {
|
|
ctx.service.utils.log('ERROR', `[${ctx.request.url}] [${ctx.logcode}] err: ${(<Error>e).stack}`);
|
|
throw e;
|
|
}
|
|
const resBody = ctx.body;
|
|
ctx.service.utils.log('INFO', `[${ctx.request.url}] [${ctx.logcode}] res: ${JSON.stringify(resBody)}`)
|
|
};
|
|
};
|
|
|