Maintain consistent logger configuration and usage patterns across the application while leveraging built-in customization options. This promotes maintainable logging practices and ensures uniform log output.
Maintain consistent logger configuration and usage patterns across the application while leveraging built-in customization options. This promotes maintainable logging practices and ensures uniform log output.
Key guidelines:
Example of proper logger configuration and customization:
// Global configuration
const app = await NestFactory.create(AppModule, {
logger: {
json: true, // Configure JSON logging globally
}
});
// Custom formatting when needed
class CustomLogger extends ConsoleLogger {
protected formatMessage(
pid: number,
logLevel: string,
context: string,
timestampDiff: number,
output: string,
): string {
// Custom format implementation
return `[${logLevel}] ${context}: ${output}`;
}
}
// Class-level logger instance
@Injectable()
class MyService {
private readonly logger = new Logger(MyService.name);
someMethod() {
this.logger.log('Operation completed');
}
}
Enter the URL of a public GitHub repository