Open ssilve1989 opened 6 months ago
Sorry for the late response. I've implemented a version where we'd use the default logger, hence you can overwrite it with app.useLogger(...)
. Would you like to verify my implementation by installing the latest beta? npm -i --save @nestjs/terminus@beta
?
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
There is no way to provide a custom logger that has injectable dependencies since you can't provide those providers (other modules, etc) to Terminus when calling
TerminusModule.forRoot()
Terminus is just taking the class-type and passing it as a
useClass
provider.Describe the solution you'd like
It would be useful if the terminus module could default to using the Nest provided logger, which can be overridden when doing
app.useLogger
. This would allow for custom loggers an application is using to just be re-used by Terminus without any additional configuration.Alternatively, the options to
TerminusModule.forRoot
could be enhanced to be able to provide the dependencies needed to create an instance of the custom logger.Teachability, documentation, adoption, migration strategy
If the first suggestion is adopted, users wouldn't have to change anything about how they declare
TerminusModule
.If a different approach is chosen, maybe it could look like
What is the motivation / use case for changing the behavior?
I have a custom
LoggerModule
that exports aLoggerService
that re-uses a single Pino logger instance. ThisLoggerService
's dependencies, in addition to the pino logger, also has some stuff in it for AsyncContext storage management to enhance logs, but the main priority is that the entire log needs to be in JSON format to be ingested by Humio in the format expected for structured logging, which my custom logger handles.Currently Terminus's
errorLogStyle
doesn't change the entire log to JSON but only the detailsbut that should really look like
in my case.