Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

369
Views
Cambiar el nivel del registrador de Winston en tiempo de ejecución en la aplicación NestJS

Necesito cambiar el nivel de Winston con mi punto final REST. He creado un servicio de registrador como este:

 @Injectable() export class CustomLoggerService implements LoggerService { private logger: Logger constructor() { this.logger = createLogger(this.getLoggerInstance()) } getLoggerInstance(customLevel?: string): LoggerOptions { const console = new transports.Console({ level: customLevel || 'info', format: format.combine( format.timestamp(), format.json(), ), }) return { exitOnError: false, handleExceptions: true, transports: [console], } } // THIS METHOD DOESN'T WORK updateLevel(level: string): void { this.logger = createLogger(this.getLoggerInstance(level)) // I also tried edit level in transports directly but not helps // this.logger.transports.forEach(t => (t.level = level)) } // implemented log messages }

Este registrador que estoy usando entonces en boostrap de aplicación como esta:

 const app = await NestFactory.create(AppModule, { logger: true }) const logger = app.get(CustomLoggerService) app.useLogger(logger)

La aplicación está utilizando internamente mi registrador y todo está bien, pero no puedo cambiar el nivel en el tiempo de ejecución.

En mis proveedores, estoy usando un registrador como este:

 @Controller('foo') export class FooController{ private readonly logger = new Logger(FooController.name) // I also tried inject it with DI like this but same behavior // constructor(private readonly logger: CustomLoggerService) {} @Get() async index(): Promise<void> { this.logger.log('This I am able to see in console') this.logger.log('This I am NOT able to see in console') } }

¿Tienes idea de lo que está mal con el código de arriba? Gracias.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!