Without arguing either side, just be aware that with varargs, some of the additional overhead is there even if debug is not enabled. That is, the compiler turns the above into:

log.debug( "User with ID {0} logged into realm {1}", new Object[ ] {userId, realm});

which creates a new Object[ ] (that is garbage collected immediately), so it's still not "free", even if it is less expensive than String concatenation.

Craig

Thanks Craig - hadn't thought about that. Even if there is still a small performance penalty (the Object[] creation), it does significantly clean up the code. I'm not strongly opinionated for or against it. But I'd be more open to a custom logging wrapper that offers some value-adds like this vs. one that is simply just another wrapper layer.

Reply via email to