Giter VIP home page Giter VIP logo

Comments (10)

BrunnerLivio avatar BrunnerLivio commented on June 11, 2024 2

@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.

BrunnerLivio avatar BrunnerLivio commented on June 11, 2024

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.

shmam avatar shmam commented on June 11, 2024

@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.

colematthew4 avatar colematthew4 commented on June 11, 2024

@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.

jrista avatar jrista commented on June 11, 2024

@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.

jrista avatar jrista commented on June 11, 2024

Thanks, @BrunnerLivio! Will check it out soon here.

from terminus.

jrista avatar jrista commented on June 11, 2024

@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.

BrunnerLivio avatar BrunnerLivio commented on June 11, 2024

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.

jrista avatar jrista commented on June 11, 2024

@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.

BrunnerLivio avatar BrunnerLivio commented on June 11, 2024

Released with v9.2.0

from terminus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.