[Question] Custom logger
Is it possible to inject custom logger into nest components ?
Wouldn't you use it as normal? E.g. for Winston i would import and configure it within your root main.ts and then just import it again in whatever file you need it which will give you the configured logger.
I don't think injecting is the right way. Just use import as you would do with RxJS or Moment.js for example.
Hi @szkumorowski, Could you explain what do you mean?
Hi,
I'm using a winston logger for application, I would like to set kind bridge for it which will resolve to use my custom logger at the end. Example with typeorm: https://github.com/typeorm/typeorm/blob/master/docs/logging.md
With above example we can implement the logger and simply pass the instance to it.
Just import it you dont need dependency injection here
You don't understand me - sorry I mean set instead of inject, I would like to set my custom logger to be used in nest components in replace for default one.
@szkumorowski
Is it possible to inject custom logger into nest components ?
Not now
Honestly, I still don't understand. Why not create a logger component and inject it into the components?
@kamilmysliwiec he wanna to override your logger
@cojack but why? Nest logger is used only to show the progress of bootstrapping the application. Winson has a completely different purpose.
@kamilmysliwiec I have just explain the question ;)
@kamilmysliwiec Not only, Its used to show errors which comes from nest components either.
@szkumorowski only when there's no custom exception filter setup. You can create your own and handle each Error in it 🙂
Btw, it might be possible, if the Logger will be part of the components, than we will be able to override it by providers ;>
@kamilmysliwiec
You should be able to substitute LoggerService like this:
import { LoggerService } from '@nestjs/common';
import { CustomLogger } from './path/to/custom_logger';
And in your components (which should be renamed to providers in v5 @kamilmysliwiec )
{ provide: LoggerService, useClass: CustomLogger }
But if this isn't possible, it should be.
@wbhob Logger doesn't belong to any scope, so it won't be possible to provide it in the module metadata.
btw components won't be renamed to providers
I should have said "could in my opinion"... I just think that either there should be explanations for why things are named as they are (that is differently from Angular, ex. @Injectable() and @Component(), or providers and components), or a review/survey of how those APIs are structured. It seems to deviate too much from Angular without good reason, but I'm sure there may be a reason that I just don't understand.
I'm sure you probably hate me for challenging you on literally everything but I honestly just want to make sure that any ambiguity is cleared up, and the transition for Angular devs to pick up Nest is clear. When writing a framework, it's critical that in addition to having well-documented APIs, that the reasoning behind them is clear. That's something Angular does very well and I'd be happy to contribute to the docs one I understand those reasonings with Nest. 👍
@wbhob no hate at all 🙂 I have explained it here https://github.com/nestjs/nest/issues/254
Yep, I saw that! That's a good point. Does Nest have support for provider objects/substitution (like useClass, useValue, useFactory)
@wbhob yes for sure, all of them
@szkumorowski has exception filter helped with your issue?