You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lenya.apache.org by si...@habmalnefrage.de on 2006/10/19 09:03:18 UTC

Logging in costum classes by using avalon mechanism

Hi folks,

guess I have another kind of low level question in terms of difficulties to answer...
Some time ago I wrote my own transformer (special thanks to all who helped me!). This transformer, in my case, extends the AbstractDOMTransformer class. Further, it imports org.apache.avalon.framework.logger.Logger. This enables to call the following within the transformer method: Logger logger = this.getLogger(); Moreover, its easy to output logger messages via e.g. logger.info("text"); at logger level: info.
I am facing the following problem now: I wrote other classes who's methods become called within my transformer. But how can I output logger messages within these classes?
I already tried to import org.apache.avalon.framework.logger.Logger; and org.apache.avalon.framework.logger.AbstractLogEnabled; Then I extended AbstractLogEnabled and tried to get a transformer within my method by the following: Logger logger = this.getLogger(); (same way as I did in my custome transformer). All this works fine in terms of compilation and runtime, but when adding to output something via logger.info("msg") / logger.error("msg") / ... I run into a java.lang.RuntimeException: and java.lang.NullPointerException during runtime. At the end, I tried to implement the LogEnabled interface as done here: http://mail-archives.apache.org/mod_mbox/cocoon-users/200607.mbox/%3C44BF29F2.1050708@tt.com.au%3E - but it doesn't work too (same exceptions).
Can someone tell me what I am doing wrong, or what I am missing?

thanks a lot for your help!

best regards

Thomas

btw: Lenya uses cocoon-2.1.7 - if someone would like to take a look at the stacktrace, just let me know plz
-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org


Re: Logging in costum classes by using avalon mechanism

Posted by Joachim Wolfgang Kaltz <jo...@uni-duisburg-essen.de>.
silentium@habmalnefrage.de schrieb:

> I am facing the following problem now: I wrote other classes who's methods become called within my transformer. But how can I output logger messages within these classes?
> (...)

Hi Thomas,

the Avalon logger is only provided (and initialized correctly) 
automatically to classes when these are Avalon components.
To use an Avalon logger in non-Avalon components, you can do this:
- pass a Logger instance to the class, for example to the constructor. 
This is easy if you are calling it from a custom transformer, just use 
getLogger(). Then, call the following code before actually using the 
logger in that class:
    ContainerUtil.enableLogging(this, logger);
    (assuming "logger" is the instance of Logger that is passed)
- make the class extend AbstractLogEnabled. That way, you avoid having 
to handle the logger instance and can call getLogger() just like you 
would in a Cocoon/Avalon component, for example
     if (getLogger().isDebugEnabled()) getLogger().debug("hello world");

You can find some examples of this kind of usage within the Lenya code.


--
Wolfgang


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org


Re: Logging in costum classes by using avalon mechanism

Posted by Dominique <op...@gmail.com>.
Hi,

your logger object is probably null , proably because the
"this.getLogger" method is
not working properly. Are you extending the right classes ?
I however am just using the log4j framework in for example my
CancelCheckoutAction class:

import org.apache.log4j.Logger;

static Logger log = Logger.getLogger( CancelCheckoutAction.class);

then you can call log.debug("etc").

You have to add the something similar as the following extract to
WEB-INF/web.xml (this patch resulted from uncommenting inside Lenya's
web-xml.xsl the similare code, but you can do it manually ):

<!--Patched by Lenya build process-->
<init-param>
<param-name>logger-class</param-name>
<param-value>org.apache.avalon.excalibur.logger.Log4JLoggerManager</param-value>
</init-param>
<init-param>
<param-name>log4j-config</param-name>
<param-value>/WEB-INF/log4j.xconf</param-value>
</init-param>


And then define your logging using /WEB-INF/log4j.xconf. I added a
appender and logger
for my "com.company.custom" package:

<appender name="CUSTOM_COMPANY" class="org.apache.log4j.FileAppender">
     <param name="File"   value="${context-root}/WEB-INF/logs/company.log" />
        <param name="Append" value="false" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d  %-5p %c.%M():%L
%x - %m%n"/>
            <!-- NOTE: Showing the method might slow down logging. In
order to improve performance use the pattern below -->
            <!--<param name="ConversionPattern" value="%-4r %d [%t]
%-5p %c %x - %m%n"/>-->
        </layout>
    </appender>



 <category name="com.company.custom" additivity="false">
      <priority value="debug"/>
      <appender-ref ref="CUSTOM_COMPANY" />
    </category>



On 19/10/06, silentium@habmalnefrage.de <si...@habmalnefrage.de> wrote:
> Hi folks,
>
> guess I have another kind of low level question in terms of difficulties to answer...
> Some time ago I wrote my own transformer (special thanks to all who helped me!). This transformer, in my case, extends the AbstractDOMTransformer class. Further, it imports org.apache.avalon.framework.logger.Logger. This enables to call the following within the transformer method: Logger logger = this.getLogger(); Moreover, its easy to output logger messages via e.g. logger.info("text"); at logger level: info.
> I am facing the following problem now: I wrote other classes who's methods become called within my transformer. But how can I output logger messages within these classes?
> I already tried to import org.apache.avalon.framework.logger.Logger; and org.apache.avalon.framework.logger.AbstractLogEnabled; Then I extended AbstractLogEnabled and tried to get a transformer within my method by the following: Logger logger = this.getLogger(); (same way as I did in my custome transformer). All this works fine in terms of compilation and runtime, but when adding to output something via logger.info("msg") / logger.error("msg") / ... I run into a java.lang.RuntimeException: and java.lang.NullPointerException during runtime. At the end, I tried to implement the LogEnabled interface as done here: http://mail-archives.apache.org/mod_mbox/cocoon-users/200607.mbox/%3C44BF29F2.1050708@tt.com.au%3E - but it doesn't work too (same exceptions).
> Can someone tell me what I am doing wrong, or what I am missing?
>
> thanks a lot for your help!
>
> best regards
>
> Thomas
>
> btw: Lenya uses cocoon-2.1.7 - if someone would like to take a look at the stacktrace, just let me know plz
> --
> Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
> Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
> For additional commands, e-mail: user-help@lenya.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org