Carsten Ziegeler wrote:
>
> Hi,
>
> I know that we had this discussion some time ago, with no real solution,
> so I thought: why not start it again?
>
> Looking at the way logging is performed in cocoon 2, I think this is
> not very fast. Here an example:
>
> <CODE>
> getLogger().debug("Creating new Templates in " + this + " for " +
> this.inputSource.getSystemId());
> </CODE>
You can use the following construct:
<CODE>
if ( getLogger().isDebugEnabled() ) {
getLogger().debug("Creating new Templates in " + this + " for " +
this.inputSource.getSystemId());
}
</CODE>
That way your string concatenation only happens when necessary.
You can also getLogger() at the beginning of the method so that the method
is only called once:
<CODE>
private void myMethod() {
Logger log = getLogger();
//do some stuff
if (log.isDebugEnabled() ) {
log.debug("Create" + " " + "Expensive" + " " + String + " " +
"Concatenations.");
}
}
</CODE>
> Even if the priority debug is disabled, the method getLogger() (from
> AbstractLoggable) is called
> returning the logger, the expensive string concatenation is performed and
> the debug() method
> of the logger is called. And these steps are done for every debug message!
>
> We should change two things here:
> a) Replace the getLogger() call with the use of an instance variable logger.
> This requires to make an own AbstractLoggable class which offers the
> logger as an instance
> variable and not via a method.
When you extend AbstractLoggable, the instance variable is called "m_logger".
the getLogger() is a convenience so that you are spared the implementation
details of class. If the instance variable name was changed (as there is no
contract to enforce this name to be the same) it will not break your code if
you use the getLogger() method. It only needs to be called once in a method
though.
> b) Before logging testing the priority.
>
> So the example above should read:
>
> <CODE>
> if (this.logger.isDebugEnabled() == true) {
> this.logger.debug("Creating new Templates in " + this + " for " +
> this.inputSource.getSystemId());
> }
> </CODE>
You shouldn't use the "== true" because that is not only implied, but violates
Sun's coding standards. It's a boolean already.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]