Closed Gbuomprisco closed 2 years ago
Sounds good! Would you like to contribute & address this issue?
I can give it a try! What do you think of the interface?
I was googling for how to disable "InstanceLoader" and came across this just now. I think this would be helpful for me as well.
I started on a PR for disabling logs for InstanceLoader. Not sure if it applies to LazyModuleLoader.
It is still very much in "WIP" status (although for some reason, GH won't let me set the PR to "draft").
I'm thinking on adding the option logger
to LazyModuleLoader#load
like the one used in NestFactory.create
(not sure if is feasible)
this.lazyModuleLoader.load(() => NestModuleClass, { logger: false })
// ... or
this.lazyModuleLoader.load(() => NestModuleClass, { logger: MyLogger })
// ... or
this.lazyModuleLoader.load(() => NestModuleClass, { logger: ['error'] })
The consumer of that provider could create a wrapper around it to avoid supplying that option every time
or maybe we should add a new public method to LazyModuleLoader
class instead? :thinking:
@Injectable()
export class AppService {
constructor(private readonly lazyModuleLoader: LazyModuleLoader) {
this.lazyModuleLoader.useLogger(false) // this implies in using a 'noop logger' under the hood
this.lazyModuleLoader.useLogger(['error'])
this.lazyModuleLoader.useLogger(MyLogger)
}
}
"interface 1" option would be great to have @micalevisk!
the disabling part is easy to achieve, but allow passing another logger instance or class ref is not. We cannot just override the logger like how is done below otherwise we will be changing the 'main' logger
in my POC I didn't find any way to implement that while allowing the logger to be injectable :/
the disabling part is easy to achieve, but allow passing another logger instance or class ref is not. We cannot just override the logger like how is done below otherwise we will be changing the 'main' logger
So let's just implement the disabling part for the time being. I can't think of a use case where using a separate logger class (specifically for lazy-loaded modules) would make sense anyway.
Let's track this here https://github.com/nestjs/nest/pull/9836
I see that https://github.com/nestjs/nest/pull/9836/files was merged, but how does one actually make use of the changes to disable logging?
@clintonb
I read all of that, and it doesn’t help me. I am using nest-commander to write CLI tools. I want to get rid of the “…dependencies initialized” messages. How can I do that?
Alternatively, given that nest-commander initializes apps in foreign (to me) manner, how would I do this on the simplest of web apps? If I have that example, I can fork/adapt commander as needed.
@clintonb
oh, that's unrelated to this issue.
Try the following instead:
nestjs
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
As a serverless user, I love the ability to lazy load services!
The only thing I would change is the ability to disable the logging of each dependent service when initializing a lazy-loaded module.
See below for the default behavior:
Describe the solution you'd like
I'd leave this to the contributors, but maybe a second parameter added to the
load
method would work okay, such as:Again, 100% up to the frameworks designer for the best way to design the API
My current workaround is to extend the logger and add a list of contexts that I skip when logging an entry.
Teachability, documentation, adoption, migration strategy
Users can choose to disable/override/change the default behavior, eg. logging each dependency that gets initialized. The API above would be one way.
What is the motivation / use case for changing the behavior?
I lazy load a lot, and I'd love to see cleaner logs.