Skip to content
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

Support to print logs based on a condition #14

Open
aneeshrelan opened this issue Oct 3, 2022 · 2 comments
Open

Support to print logs based on a condition #14

aneeshrelan opened this issue Oct 3, 2022 · 2 comments
Labels
good first issue Good for newcomers

Comments

@aneeshrelan
Copy link
Contributor

Example:

logger.warn("Exceeded maximum retries to fetch details", count => count > 3);

will only print the log when the condition is met

@aneeshrelan aneeshrelan added the good first issue Good for newcomers label Oct 3, 2022
@su-mit
Copy link

su-mit commented Oct 3, 2022

Hi @aneeshrelan, I would like to work on this issue can u please provide some more context over it

@aneeshrelan
Copy link
Contributor Author

aneeshrelan commented Oct 5, 2022

Hey @su-mit

We want to log the line to actually execute based on a provided condition. This is useful in case of heavy processing code (>10k ops per sec) and while it is good to log every event, it's best to log at a verbose level (debug, trace) and log some aggregate results at an INFO level

Similarly the original example, where we might have exponential retries put in and should log after every 5 failed retries

Example: logger.warn("Retry failed", count => count % 5 === 0)

For the implementation, the logger method currently allows the following:

  1. logger.level("Simple Message");
  2. logger.level("Processed user", {id: <user-id>, name: <user-name>})

So, we should have a method of the prototype:

logger.level(msg: string);

logger.level(msg: string, Record<string, unknown>);

logger.level(msg: string, Record<string, unknown>, EvaluationFunction: Function);

logger.level(msg: string, EvaluationFunction: Function);

Hope this helps, feel free to comment if you have more questions

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

No branches or pull requests

2 participants