Skip to content

feature: logger hook functions #10

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

Merged
merged 2 commits into from
Apr 6, 2025
Merged

Conversation

idbenami
Copy link
Contributor

@idbenami idbenami commented Apr 3, 2025

added the ability to add hooks functions per each log level or all of them.
hooks are passed in the options param in the module root functions.

example:

ContextLoggerModule.forRoot({
  hooks: {
    error: [(message, bindings) => {
      generalErrorsCounter.add(1, bindings);
    }]
  }
})

@AdirD AdirD requested a review from Copilot April 6, 2025 05:54
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

}

[...(hooks[level] || []), ...(hooks['all'] || [])].forEach((hook) => {
hook(message, bindings);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand the purpose behind this, you want to be able to shove side effects right before the log is sent? But the hooks are set one time during app bootstrap, why not use the context interceptor to enrich the context and such new fields enrichment will be done automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn’t meant for enriching the logs themselves, but rather for triggering small side effects right before or after a log is sent (could be changed) - like tracking metrics or triggering alerts.

It’s meant as a lightweight runtime hook without needing to run the same block of code before/after each log, wrap logger functions or modify individual log calls.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as in "also send a sentry when an error is logged?"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, for example..

@AdirD AdirD merged commit b3f9621 into AdirD:main Apr 6, 2025
1 check passed
Copy link

github-actions bot commented Apr 6, 2025

🎉 This PR is included in version 1.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants