我见过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。