如何将Koa上下文加载到Winston记录器中间件中?

我有一个koa服务器,前端已经通过koa的上下文传递了一些与用户相关的数据。在我的koa应用中,可以通过执行以下操作获取上下文:

// app.ts

import { Context } from "koa";

this.app.use(async (ctx: Context,next: () => Promise<any>) => {
    // Here I can read what's in ctx
});

但是,我正在使用apolloServer的{​​{1}}(https://www.apollographql.com/docs/apollo-server/api/apollo-server/#apolloserverapplymiddleware)来加载Winston logger实例。

我的Winston记录器实例如下所示:

applyMiddleware

我想获取要通过Winston.createLogger({ format: Winston.format.combine( Winston.format.timestamp(),// I want to get the data from ctx to insert into here )...... }) 传递到中间件的数据,或者直接从中间件从app.ts中读取。我最好的方法是什么?

wyaizjj 回答:如何将Koa上下文加载到Winston记录器中间件中?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2959505.html

大家都在问