I am using NestJS as a backend service in which I want to add some logger for better logging mechanism.Though NestJs has a default logger for logging but I am using Winston in my application. I want functionality so I can get a class name also in logs to which log belongs to.
Using NestJs default logger I can achieve this using below code in particular file
private readonly logger = new Logger(AppService.name);
By using above code I am able to get class name along with logs which is AppService
.
But I am using nest-winston package in my application. How can I get the same thing with it?
Below is my code:
import { Module } from '@nestjs/common';
import { WinstonModule,utilities as nestWinstonModuleUtilities } from 'nest-winston';
import * as winston from 'winston';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import * as path from 'path';
@Module({
imports: [ WinstonModule.forRoot({
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json(),
nestWinstonModuleUtilities.format.nestLike('MyApp', { prettyPrint: true }),
),
transports: [
new winston.transports.Console(),
new winston.transports.File({
dirname: path.join(__dirname, '../log/info/'), //path to where save logging result
filename: 'info.txt', //name of file where will be saved logging result
level: 'info',
}),
],
}),],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
What thing do I need to change?