Comments (10)
@jrista I published a beta with this feature. npm i @nestjs/terminus@beta
.
Docs are at the moment found in the PR #2202. Could you verify whether this is what you expected?
from terminus.
Sorry for the late response. It is possible to overwrite the logger, by simply adding your custom implementation within NestFactory.create
:
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:
...
LOG:
TerminusModule dependencies initialized
LOG:
AppModule dependencies initialized
LOG:
HealthController {/health}:
LOG:
Mapped {/health, GET} route
LOG:
Nest application successfully started
ERROR:
Health Check has failed! {"asdf":{"status":"down","message":"getaddrinfo ENOTFOUND doesnotexistforsure.io"}}
Or were you for looking for something else?
from terminus.
@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.
from terminus.
@BrunnerLivio we are using a module/service extending the ConsoleLogger and injecting it throughout our application, so this wouldn't work for us
from terminus.
@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 TerminusModuleOptions
object only supports one option, errorLogStyle
, which seems to only control whether error logs are pretty or json. There is no way to disable the logging though, which even that, would be of use to us to get around this issue we have of our logs being 97% or more terminus logging (and 99% of that, is "health ok" basically.)
from terminus.
Thanks, @BrunnerLivio! Will check it out soon here.
from terminus.
@BrunnerLivio Had a chance to look at the updates. To make sure I understand, this adds a publicly configurable logger: boolean
flag? I did see that internally, there were some changes to separate out error logging from other logging. That is intriguing, and it makes me wonder if there might be any way to expose two configurable flags, one for general logging, and a separate one for error logging.
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)?
from terminus.
adds a publicly configurable logger: boolean flag
Yes, but also you can add your own logger. Hence you can filter out any messages if you'd like
Custom Logger
app.module.ts
@Module({
imports: [
TerminusModule.forRoot({
logger: TerminusLogger,
}),
],
...
})
export class AppModule {}
terminus-logger.service.ts
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
}
}
filled up with benign logging that has no value: Health check succeeded
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
I was thinking of adding log level support but for now since only errors are being logged a boolean would suffice
from terminus.
@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!
from terminus.
Released with v9.2.0
from terminus.
Related Issues (20)
- After PR #1970 (update from 9.0.0 to 9.1.0) there is an error with TERMINUS_ERROR_LOGGER HOT 2
- NestJS Terminus has an undeclared dependency on Axios HOT 1
- Typescript issues with axios >= 0.27 HOT 1
- Named swagger schema HOT 4
- Optional peerDependencies are not declared in manifest
- Throwing HealthCheckError in synchronous HealthIndicatorFunction does not work properly HOT 5
- Nest could not find MikroORM element (this provider does not exist in the current context) HOT 1
- MicroserviceHealthIndicator pingCheck() failed when error is undefined HOT 2
- MikroOrmHealthIndicator does not work with the `defineConfig` helper HOT 4
- this library does not support Nestjs 10.0.0 HOT 5
- On shutdown, health request before signal interrupted with ECONNREFUSED
- Cached responses 200 -> 304 HOT 6
- HttpHealthIndicator.responseCheck not handles network errors HOT 1
- Adding a gracefulShutdownTimeout option for 0-downtime deployment on Kubernetes HOT 6
- nest10 health check return Service Unavailable Exception HOT 1
- Mikro ORM check returns healthy although not connected HOT 7
- Schema does not match health-indicator-result interface HOT 7
- DiskHealthIndicator always reports: "Used disk storage exceeded the set threshold" HOT 1
- Logger Enhancements
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terminus.