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

Add condition to logger #412

Closed

Conversation

jbicker
Copy link
Contributor

@jbicker jbicker commented Dec 15, 2023

Sometimes (especially while development) it is useful to only log under certain conditions. This small enhancement enables to write such conditional logs like this instead of if blocks and console.log:
this.logger.condition(edge.id === 'edge1').log(this, 'Edge Bounds are: ', edge.bounds);

Copy link
Contributor

@spoenemann spoenemann left a comment

Choose a reason for hiding this comment

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

I'm not sure about that – a plain old if block still has advantages:

logger.condition(bla).log(expression that is expensive to compute);

vs.

if (bla) {
    logger.log(expression that is expensive to compute);
}

In the first case the "expression that is expensive to compute" is always evaluated. In the second case, it's only evaluated when the condition is met.

I'm afraid that the proposed API can lead to bad practices.

@jbicker jbicker closed this Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants