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

Make disabled log prints not compute the string to log #261

Open
ailrst opened this issue Oct 24, 2024 · 0 comments
Open

Make disabled log prints not compute the string to log #261

ailrst opened this issue Oct 24, 2024 · 0 comments
Labels
refactor Refactor to clean up code or design

Comments

@ailrst
Copy link
Contributor

ailrst commented Oct 24, 2024

Currently I log calls eagerly evaluate their parameters, causing wasted work for log calls to levels below the currently enabled log level. This is especially a problem if we compute many large expensive strings just to throw them away.

We can refactor the logger to lazily evaluate its parameters instead:

scala>
def logDebug(v: => String) = {
            if (level > 1) {
               println("log : " + v)
            } 
       }
scala> level = 0
level: Int = 0
scala> logDebug(s"${println("hello")}")
scala> level = 2
level: Int = 2
scala> logDebug(s"${println("hello")}")
hello
log : ()

refactor the logger to lazily compute the string to log, ideally we can simply

@ailrst ailrst added the refactor Refactor to clean up code or design label Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Refactor to clean up code or design
Projects
None yet
Development

No branches or pull requests

1 participant