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

[BUG] The way you are using a logDebug method, defeats the purpose of isDebugEnabled #23

Open
ksmith1787 opened this issue Jul 10, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ksmith1787
Copy link

Describe the bug
The reason we use the logger.isDebugEnabled() if statement is so that we avoid calling logger.debug if Debug is not enabled. Best practice is to evaluate this inline. Also best practice is only to include this isDebugEnabled check is when the string contains something that requires evaluation or has a method call, such as object.toXml() or map.toString(). It's best practice not to use the isDebugEnabled test when the string is just a concatenation of strings and string variables. Hence burying the isDebugEnabled method in another method, for something like logDebug("This is a string"), is overkill (not needed), and for something like logDebug("This is a map: "+map.toString()) it defeats the purpose because the system has to execute the toString() method even if the debug level is not enabled.

For instance:
logDebug("Processing attribute request: " + attributeRequest.toXml());
this statement expands the toXml() method even if debug level is not enabled.

Expected behavior
Remove the logDebug() method call and replace with if(logger.isDebugEnabled())logger.debug(""); only when the string has a method call or object reference, and replace with simple logger.debug("string"+variable+etc); for simple strings.

@ksmith1787 ksmith1787 added the bug Something isn't working label Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant