0

I want to use winston logging module in my node application and I am using nest framework.

So I installed

yarn add nest-winston
yarn add winston

and in my app.module.ts

WinstonModule.forRoot({
  format: winston.format.combine(
    winston.format.timestamp(),
    winston.format.json(),
  ),
  transports: [
    new winston.transports.File({
      dirname: process.env.LOG_FILE_PATH,
      filename: 'info.log',
      level: 'info',
    }),
    new winston.transports.File({
      dirname: process.env.LOG_FILE_PATH,
      filename: 'error.log',
      level: 'error',
    }),
  ],
}),

and in my contrller file i can inject like this

constructor(@Inject(WINSTON_MODULE_NEST_PROVIDER) private readonly logger: LoggerService) { }

and this is working fine.

Now I have DB class that is static with static methods. So there will be no constructor. So how can I inject in this case.

And in my main.ts there is no class so in that too how can i get the logger instance.

Sunil Garg
  • 14,608
  • 25
  • 132
  • 189
  • This is dup of https://stackoverflow.com/questions/65847961/is-there-a-way-to-use-static-method-with-dependency-injection-in-nestjs TL;DR: Thats not possible without starting up nest app – Alexey Petushkov Oct 19 '21 at 11:21

0 Answers0