You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Alan Hodgkinson <al...@softxs.ch> on 2002/09/13 12:50:32 UTC

Re: [SUMMARY] How can I log in non-Cocoon Java classes? --> Improved solution

Dear Piroumian,

> > This explaines how to implement Cocoon-style logging, in a
> > <snip/>
> > 1. The class must extend AbstractLogEnabled.
> 
> ..Isn't it enough to implement the LogEnabled interface?
> <snip/> and provide methods for getting the logger?

Yup, in Cocoon/Avalon, like Perl, there's more than one way to do it. :)
I just tried it your technique and it works just fine.

> The AbstractLogEnabled is a utility helper class and the problem with it is
> that you'll have to extend it, which is not possible in all the cases, e.g.
> if your class extends some app-specific base class and you can't change it.

This is, in fact, a more flexible solution. In my simple case, I just
needed 
logging from a bean and the extend was possible. With your method,
you're 
free from the restriction. You do have the (minimal) overhead of
implementing 
the LogEnabled interface, but in exchange you get the flexibility of not 
having to extend any log related classes.

For the record, here's a summary of the improved solution:

  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.LogEnabled;

  class SomeBean extends SomeOtherBean implements LogEnabled {
    ..
    // The LogEnabled interface is one method: enableLogging
    private Logger logger;
    public void enableLogging( Logger logger ) { 
      this.logger = logger; 
    }

    // Example method that writes to the log
    public void setThing( String thing ) {
      logger.debug( "SomeBean: thing = " + thing );
      ...
    }
  }

Note that you still have to call enabledLogging() with a valid Logger,
before you use write to the log, as I explained in original summary.

BTW: By popular demand, I published my original summary in the Wiki. 

  http://outerthought.net/wiki/Wiki.jsp?page=JavaLogging

But due to your input, it's already out of date :). I'll update it.

Thanks your help and..

Best wishes,

Alan.

---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>