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

Log functions with lazily evaluated parameters #77

Open
Brandhoej opened this issue Oct 13, 2022 · 0 comments
Open

Log functions with lazily evaluated parameters #77

Brandhoej opened this issue Oct 13, 2022 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Brandhoej
Copy link
Contributor

Brandhoej commented Oct 13, 2022

The log functions (debug, info, trace and such) evaluates the parameters even though the urgency blocks the log. For this reason log functions should also provide a way for users to specify a call where the parameters are lazily evaluated. An example is:

    public static void debug(Supplier<String> supplier) {
        if (urgency.level >= Urgency.Debug.level) {
            out(format(supplier.get(), Urgency.Debug));
        }
    }

    // Calling it would look like the following:
   Log.debug(() -> "Hello, World!");

Here the Supplier is only evaluated if we need its value.

Originally posted by @Brandhoej in #74 (comment)

@Brandhoej Brandhoej mentioned this issue Oct 13, 2022
@Brandhoej Brandhoej changed the title Supplied log functions Log functions with lazily evaluated parameters Oct 13, 2022
@Brandhoej Brandhoej added enhancement New feature or request good first issue Good for newcomers labels Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant