cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carsten Ziegeler" <cziege...@sundn.de>
Subject AW: [C2]: Performance and logging
Date Tue, 07 Aug 2001 13:52:55 GMT
> Berin Loritsch wrote:
>
> 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>
>
Yes, this reduces the overhead a little bit, but I still have it in every
method although the logger is only set once for each object.

> > 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.
>
That's the reason why I thought writing an own AbstractLoggable class
which enforces the name of the instance variable to be e.g. logger
or something like that.

> > 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.
>
Well, there are so many coding standards and consulting java beginners
for more than 3 years now, I found out that it is for beginners more
readable to add the "== true" or "== false" to boolean expressions.
But fortunately this is not the topic of this email...


Carsten
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message