koa-bunyan-logger中的ctx.time()怎么用的
试着用koa-bunyan-logger日志处理,但是不知道为什么,没有官方的演示的效果
const setLogger = (app) => {
app.use(koaLogger(logger));
app.use(koaLogger.timeContext());
app.use(async function (ctx, next) {
ctx.time(ctx.path);
await next();
ctx.timeEnd(ctx.path);
ctx.log.info({method: ctx.method, path: ctx.path, http: ctx.status},
`${ctx.method} => ${ctx.path} => ${ctx.status}`);
});
};
打出的日志为
{"name":"demo","hostname":"******.local","pid":31265,"level":30,"method":"GET","path":"/api/health/status","http":200,"msg":"GET => /api/health/status => 200","time":"2019-03-21T06:29:05.678Z","v":0}
没有官方出现的"label":"get data","duration":102
{"name":"koa","hostname":"localhost","pid":9228,"level":10,"label":"get data","duration":102,"msg":"","time":"2014-11-07T01:45:53.711Z","v":0}
{"name":"koa","hostname":"localhost","pid":9228,"level":10,"label":"serialize","duration":401,"msg":"","time":"2014-11-07T01:45:54.116Z","v":0}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论