NestJS:如何在微服务应用程序中全局记录请求模式

时间:2019-12-03 16:13:34

标签: nestjs

我见过some answers,那里的人们解释了如何在NestApplication中设置全局记录器。我想在NestMicroservice中实现相同的目的:记录从微服务请求的消息模式。

作为一个例子,我们有以下控制器:

@Controller('/auth')
export class AuthController {
    @MessagePattern({ cmd: '/login' })
    async login(auth: AuthDto) {
        return true;
    }
}

the official way to add an interceptor之后,我得到了

@Injectable()
export class LoggingInterceptor implements NestInterceptor {
    intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
        console.log('Before...');

        const now: number = Date.now();
        return next.handle().pipe(tap(() => console.log(`After... ${Date.now() - now}ms`)));
    }
}

我可以在控制台中看到日志,但是我也想记录微服务命令:/auth/login。该怎么办?

因此,我们可以在生产中概述使用了哪些微服务API。

0 个答案:

没有答案