Complete the code to import the Logger from NestJS.
import { [1] } from '@nestjs/common';
The Logger class is imported from '@nestjs/common' to enable logging in NestJS.
Complete the code to create a Logger instance inside a service class.
private readonly logger = new [1](MyService.name);The Logger class is instantiated with the class name to tag logs properly.
Fix the error in logging an exception message inside a catch block.
catch (error) {
this.logger.[1]('Error occurred:', error.message);
}The error method logs error-level messages including exceptions.
Fill both blanks to log the stack trace of an exception.
catch (error) {
this.logger.[1]('Exception stack:', error.[2]);
}Use error to log the message and stack to show the full stack trace of the exception.
Fill all three blanks to create a custom exception filter that logs exceptions.
import { ExceptionFilter, Catch, ArgumentsHost, [1] } from '@nestjs/common'; @Catch() export class AllExceptionsFilter implements ExceptionFilter { private readonly logger = new [2](AllExceptionsFilter.name); catch(exception: any, host: [3]) { this.logger.error('Exception caught:', exception.stack); const ctx = host.switchToHttp(); const response = ctx.getResponse(); response.status(500).json({ message: 'Internal server error' }); } }
Import Logger and ArgumentsHost from '@nestjs/common'. Instantiate Logger for logging. Use ArgumentsHost type for the host parameter.