On 25.03.2009, at 09:55, Jeremy Haile wrote:
I argued against writing our own wrappers in the past, but we have
created some wrappers on another project that I feel are
beneficial. Since we're discussing going through the code and
replacing all of our log calls, I thought I'd mention it here.
Our wrapper takes in var-args and internally uses the MessageFormat
class to substitute in arguments. This removes the problem when
logging of string concatenation being slow since the string
concatenation only takes place if the log level is set.
So code that used to look like this:
if( log.isDebugEnabled() ) {
log.debug( "User with ID [" + userId + "] logged into realm [" +
realm + "]" );
}
can now look like:
log.debug( "User with ID {0} logged into realm {1}", userId, realm);
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
This is cleaner and doesn't incur the cost of string concatenation
even if the log level is not set to debug. Under the hood it just
calls SLF4J. If the last argument is an exception, the stacktrace
gets logged.
Thoughts?
Jeremy
On Mar 25, 2009, at 10:44 AM, Les Hazlewood wrote:
Now that Maven is in place and things feel like they're on rails,
I'd like
to revisit the SLF4J issue.
Can we remove commons-logging in favor of SLF4J now?
Don't worry, I'm not proposing our own wrapper on top of it ;) We
could
just use the slf4j API directly in code and move on. Is that ok with
everyone?
- Les