ntegral / nestjs-sentry

Provides an injectable sentry.io client to provide enterprise logging nestjs modules
ISC License
380 stars 98 forks source link

[Feature Request] Allow to disable console logging or allow to provide custom logger #53

Open doctorrokter opened 3 years ago

doctorrokter commented 3 years ago

Hey!

In my Nest project I have a custom Logger implementation which is optimized for SumoLogic format. In case of errors I use my logger to print logs and @ntegral/nestjs-sentry to send error to Sentry. The problem is that lib by default also prints logs in default Nest format because of SentryService extends ConsoleLogger.

I would to have an ability to disable that default behaviour in order to keep my logs clean and without duplication.

Or, as another solution, would be great to have an ability to provide own custom logger to @ntegral/nestjs-sentry.

What do you think about that?

holm commented 3 years ago

I was just looking to solve the same problem. It would be nice to be able to separate these concerns.

doctorrokter commented 3 years ago

@holm for now I have a temp workaround in my project:

Definetely worth a try to fork the repo, get rid of inheritance and do a PR.

Rather than extending ConsoleLogger class would be better to implement LoggerService interface instead. In that case we still will have NestJS-like logging API. And in addition we could provide custom logger class (or instance) during SentryModule initialization to let SentryService write custom logs if we want.

doctorrokter commented 3 years ago

@ntegral @holm created PR for that FR, hope it looking not bad:

https://github.com/ntegral/nestjs-sentry/pull/54

holm commented 3 years ago

Awesome. Thanks for doing that. Added a few comments on the PR, just from my perspective, although of course this is not my library at all :)

foxted commented 2 years ago

Looks like by using the instance directly, it doesn't log into the console. So using: this.sentry.instance().captureMessage() instead of this.sentry.log().