Hi Will,

My fault. I thought it would work the way I explained it ... but it doesn't
... However, the correct way to do it is even simpler ... :-)
Your test case instance inherits from ServletTestCase, JspTestCase or
FilterTestCase. In turn, they all inherit from AbstractTestCase which
defines a logger object, which is correctly initialized when you use it in
your test methods.

So here is the correct way to do it :

public class MyTestCase extends ServletTestCase
{
  public void beginXXX(WebRequest theRequest)
  {
     logger.debug("beginXXX");
  }

  public void testXXX()
  {
     logger.debug("testXXX");
   }

  public void endXXX(WebResponse theResponse)
  {
     logger.debug("endXXX");
  }
}

You still need to configure correctly the Log4j Category in the properties
files.
Thanks
-Vincent

----- Original Message -----
From: "William Lee" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, September 20, 2001 11:13 PM
Subject: Re: Logging using log4j


> Thanks for you reply. I tried your code below but I got an error saying
that the LogService I got from getInstance() needs to be initialized.
However, the init() call for LogService takes in an argument of a file.
What should I do in this case?
>
>
> Will
>
>
> > Here is an example of code :
> >
> > import org.apache.cactus.util.log.*;
> >
> > public class MyTestCase extends ServletTestCase
> > {
> >   private Log logger =
> > LogService.getInstance().getLog(MyTestCase.class.getName());
> > [...]
> >   public void testXXX()
> >   {
> >      logger.debug("something");
> >   }
> > }
> >
> > In this example, we've used the class name as the Log4j Category, so we
need
> > to add this category to the Log4J configuration. You should either edit
the
> > log_server.properties file in cactus.jar and add :
> >
> > # Properties for configuring Log4j
> > # This is the configuring for logging on the server side
> >
> > log4j.appender.cactus = org.apache.log4j.FileAppender
> > log4j.appender.cactus.File = cactus_server.log
> > log4j.appender.cactus.Append = false
> > log4j.appender.cactus.layout = org.apache.log4j.PatternLayout
> > log4j.appender.cactus.layout.ConversionPattern = %d{ABSOLUTE} [%t] %-5p
> > %-30.30c{2} %x - %m %n
> >
> > log4j.category.org.apache.cactus = DEBUG, cactus
> > log4j.category.my.package = DEBUG, cactus
> >
> > You can add an appender if you wish to have your logs generated in a
> > separate file.
> > The other option is not to touch at the cactus jar, create a
> > log_server.properties file and ensure it is put in the classpath
*before*
> > the cactus.jar
> >
> > -Vincent
> >
> >
> >
>
>
>
> --
> William Lee (Will)        | Sendmail Inc.
> Email:  [EMAIL PROTECTED] | http://www.sendmail.com
> Tel:    (510) 594-5505    |
>
>

Reply via email to