cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcus Crafter <craft...@fztig938.bank.dresdner.net>
Subject Re: How can I log in non-Cocoon Java classes?
Date Wed, 11 Sep 2002 16:00:27 GMT
Hi Alan,

On Wed, Sep 11, 2002 at 04:21:21PM +0000, Alan Hodgkinson wrote:
> 
> Can someone give me a hint on how to implement Cocoon logging
> in Java classes that don't extend from the 'Abstract{Cocoon}
> classes (I.e. AbstractAction, AbstractReader, etc.)?
> 
> For example, how would I implement logging in a really simple 
> Java Bean, that otherwise wouldn't have to know anything about 
> cocoon?

	Is this class to be used from within Cocoon, or is it a completely
	separate application ?
	
	If it's within Cocoon, read on, if not, then have a look at the
	logkit examples on jakarta.apache.org.
	
> I had hoped that I could 'extend AbstractLogEnabled' and 'implement
> LogEnabled' in my class. I've searched for clues in all the 
> examples, but they always extend some Cocoon-specific class (that 
> magically make the logging work).
> 
> My code is roughly the following:
> 
>   import org.apache.avalon.framework.logger.AbstractLogEnabled;
>   import org.apache.avalon.framework.logger.LogEnabled;
>   import org.apache.avalon.framework.logger.Logger;
> 
>   public class MyClass
>       extends AbstractLogEnabled
>       implements LogEnabled
>   {
>     private Logger logger;
>     public void enableLogging(Logger logger) {
>       this.logger = logger;
>     }

	you don't need this method and variable if you extend from
	AbstractLogEnabled, as they are already provided for you in the
	AbstractLogEnabled class.

>     public void myMethod() {
>       getLogger().debug( "msg.." ); // <-- getLogger() returns null!
>     }
>   }
> 
> The problem is that getLogger() always returns null. I suspect
> that I need to implement some other interface too.

	Yes, getLogger() returns null if logging hasn't been enabled on
	that object. :)
	
	LogEnabled is actually an Avalon Component lifecycle stage and the
	method enableLogging() is automatically invoked on components that
	implement this interface by the Avalon component manager (thats the
	magic part you're referring to).
	
	That may sound confusing if you've never heard of Avalon before :)
	so if you're not writing a Component, and simply want to do some
	logging in your object from within your Cocoon application, call
	the enableLogging() method on your object (defined in
	AbstractLogEnabled) and pass into it a Logger object retrieved
	from Cocoon somewhere (ie. sitemap component, logkit manager, etc).
	
	Hope that helps.
	
	Cheers,
	
	Marcus

-- 
        .....
     ,,$$$$$$$$$,      Marcus Crafter
    ;$'      '$$$$:    Computer Systems Engineer
    $:         $$$$:   ManageSoft GmbH
     $       o_)$$$:   82-84 Mainzer Landstrasse
     ;$,    _/\ &&:'   60327 Frankfurt Germany
       '     /( &&&
           \_&&&&'
          &&&&.
    &&&&&&&:

---------------------------------------------------------------------
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:     <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>


Mime
View raw message