I did not express clearly so you partly misunderstood (the code you wondered about was in fact in the act() method of my custom action to create and initialize my custom non-Cocoon class) but you helped me anyway, thanks Marcus : indeed the 2 loggers I have have the same ID (LogKitLogger@2d5534), and it works now... I forgot "this." before "getLogger()" in the bottom code, damn ! :-p
So maybe there is a slight correction to http://outerthought.net/wiki/Wiki.jsp?page=JavaLogging with some "this." in this section ? import org.apache.avalon.framework.logger.AbstractLogEnabled; public class SomeClass extends AbstractLogEnabled { public void someMethod() { ... getLogger().debug( "Hello, log. It worked!" ); getLogger().info( "Hello, log. Here is info" ); getLogger().error( "Hello, log. Here is an error" ); //..etc. ... } } Babs after a good lunch, so better coding now. ----- Original Message ----- From: "Marcus Crafter" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, September 19, 2002 1:59 PM Subject: Re: troubles with logging of non-cocoon classes... > Hi Barbara, > > On Thu, Sep 19, 2002 at 12:04:07PM +0200, Barbara Post wrote: > > I get a NPE. I followed : > > http://outerthought.net/wiki/Wiki.jsp?page=JavaLogging method 1. > > > > First class is a classical custom Action, which has its logger defined in > > the sitemap. > > Logging of this action works fine. > > ok. > > > In this action I create an instance of a custom class that extends > > AbstractLogEnabled : > > > > TaminoAccess tamac = new TaminoAccess(); (the void > > constructor does anything) > > tamac.enableLogging(this.getLogger()); > > tamac.setUri(this.uri); > > Where exactly this this code above ? I suspect it's in the > constructor of your custom action ? > > If this is the case then the call to 'this.getLogger()' will > return null because the Avalon component manager won't have yet > enabled logging on that sitemap component (and hence your > non-cocoon class won't have a logging object to log to) > > To fix this, implement Initializable on your custom action and add > the code to create and set the logger on your non-cocoon class there. > > The initialize() method on your action will be called well after > enableLogging() by the ComponentManager, so you should have a valid > logging object then. > > (BTW - If the variable happened to be created at within the class > (ie. not in the constructor) then an alternative could be to overload > enableLogging() on your custom action and propogate the logger > object there). > > If that's not the case, can you print out what 'this.getLogger()' > returns and set us in a stacktrace of the NPE. > > Hope that helps. > > Cheers, > > Marcus > > > > in the method directly called by setUri(this.uri) I try to log as follow : > > > > if (getLogger().isDebugEnabled()){ > > getLogger().debug("tamino server : " + this.taminoServer); > > getLogger().debug("tamino database : " + this.taminoDatabase); > > getLogger().debug("tamino collection : " + this.taminoCollection); > > } > > > > This throws a NPE. > > -- > ..... > ,,$$$$$$$$$, 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: <[EMAIL PROTECTED]> > For additional commands, e-mail: <[EMAIL PROTECTED]> > --------------------------------------------------------------------- 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: <[EMAIL PROTECTED]> For additional commands, e-mail: <[EMAIL PROTECTED]>
