You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Martin Marinschek <ma...@gmail.com> on 2006/03/07 21:10:07 UTC

Logging - again

Hi *, Hi Simon,

logging again - what do we do with static methods - do we have to get
all of them out?

or should we be calling getLog on every logging attempt?

regards,

Martin

--

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Re: Logging - again

Posted by Werner Punz <we...@gmx.at>.
Simon Kitching schrieb:

> Note in particular that both SLF4J and java.util.logging have exactly
> this same problem when used with an underlying logging library that is
> container-aware, so avoiding static loggers is something that really
> should be done anyway.
> 
+1 for a vote on the most widely used antipatterns ever...
even plugins produce static logging code!


Re: Logging - again

Posted by Simon Kitching <sk...@apache.org>.
On Tue, 2006-03-07 at 21:10 +0100, Martin Marinschek wrote:
> Hi *, Hi Simon,
> 
> logging again - what do we do with static methods - do we have to get
> all of them out?
> 
> or should we be calling getLog on every logging attempt?

Yep, even static methods must avoid logging via a static logger :-(

In general, calling LogFactory.getLog within the static method would be
the appropriate solution:
  public static void doStuff(...) {
    Log log = LogFactory.getLog("stuff");
    log.warn(...);
  }

If the static method has a reference to some object then it could
retrieve a logger from it, eg
  public static void doStuff(AppContext context, ...) {
    context.getStuffLog().warn("oops");
  }
This doesn't seem widely applicable though.

Fancier solutions like retrieving log objects from a collection in a
thread-local variable are probably not worth trying; the
LogFactory.getLog method isn't that slow.


I've created a wiki page with more info on this subject if you're
interested:
  http://wiki.apache.org/jakarta-commons/Logging/StaticLog

Note in particular that both SLF4J and java.util.logging have exactly
this same problem when used with an underlying logging library that is
container-aware, so avoiding static loggers is something that really
should be done anyway.

Cheers,

Simon