-
-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow custom logger implementation for health check service #2068
Comments
Sorry for the late response. It is possible to overwrite the logger, by simply adding your custom implementation within const app = await NestFactory.create(AppModule, {
logger: {
...console,
log: (msg: string) => {
console.log('LOG:');
console.log(msg);
},
error: (msg: string) => {
console.error('ERROR:');
console.error(msg);
},
},
}); Example log with Terminus:
Or were you for looking for something else? |
@BrunnerLivio hello! Is there any way to apply a custom logger just to the health check service? I wanted to reduce our logs to the health check service to just one line but leave the logs the same for the rest of my application. |
@BrunnerLivio we are using a module/service extending the ConsoleLogger and injecting it throughout our application, so this wouldn't work for us |
@BrunnerLivio As with the others, including from some previously closed issues, I would like to control where Terminus logging goes. Its not just a matter of changing how it logs to the main nest.js log...I want to prevent Terminus logging from going to the main log entirely, which pretty much means being able to supply an alternative logger. The main problem we are facing is, Terminus hard-logs (we can't control it), every few seconds (frequency of our health checks in AWS), and that completely fills up 97% of our logs with stuff that is of no value. We have a real hard time finding error or warning logs, or even just debug logging, when we actually have to troubleshoot something, because Terminus offers no way to even disable its logging, let alone redirect it. Currently, as far as I can tell, the |
Thanks, @BrunnerLivio! Will check it out soon here. |
@BrunnerLivio Had a chance to look at the updates. To make sure I understand, this adds a publicly configurable The main issue we have run into lately is that our logs get filled up with benign logging that has no value: Health check succeeded. We do want to know when health checks fail, though... I am not sure if that is actually what your error logging is used for, I kind of suspect it may in fact be used for internal errors in terminus, not really failed health checks. So, the new flag is definitely welcome, but I am wondering if we could make this better, by allowing...oh, maybe it could just be a log level configuration, where we can either turn logging off completely, only log when one or more health checks fail, or log everything, on the general logger (and always allow the error logger to log internal errors for terminus itself)? |
Yes, but also you can add your own logger. Hence you can filter out any messages if you'd like Custom Logger
@Module({
imports: [
TerminusModule.forRoot({
logger: TerminusLogger,
}),
],
...
})
export class AppModule {}
import { Injectable, Scope, ConsoleLogger } from '@nestjs/common';
@Injectable({ scope: Scope.TRANSIENT })
export class TerminusLogger extends ConsoleLogger {
error(message: any, stack?: string, context?: string): void;
error(message: any, ...optionalParams: any[]): void;
error(
message: unknown,
stack?: unknown,
context?: unknown,
...rest: unknown[]
): void {
//noop
}
}
What do you mean by that? Terminus does not log this message. Are you sure this isn't something from your side? Terminus only logs error messages |
@BrunnerLivio Hmm, well, its possible its another logger... I'll have to dig around a bit. If its not actually Terminus, then that's good. ;) We may have injected some other logger, or something that is logging... A customizable logger should do for our needs though! Thanks! |
Released with v9.2.0 |
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
My team uses a logger implementation with a custom winston transport to our logs host provider for all of our services. When a health check fails, the HealthCheckService logs using the built-in nest logger.
Describe the solution you'd like
We would like to be able to have the HealthCheckService log using a custom logger implementation, ideally something similar to how custom loggers are already used for regular controller modules.
Teachability, documentation, adoption, migration strategy
Custom logger documentation already exists.
What is the motivation / use case for changing the behavior?
Detailed above
The text was updated successfully, but these errors were encountered: