im going to assume a few things:
you only want one config file per web application
you only want one appender, a filewriter that writes to a file

directions:

you should use an servlet that is loaded when tomcat starts up (use
documentation on log4j site to do this)

this servlet can take a parameter from the web.xml file that tells it where
its configuration file is located.

this configuration file should setup a single appender that writes to a file
that is specified in the configuration file. you should set this appender as
the rootCategory in the config file.

in your classes, you should declare a static Category (which by default will
use the rootCategory settings), then using statements like
cat.warn("blahblah"); to print out log statements to the file specifiied in
the configuration file.


the details on each step ARE available in the log4j documentation.

matt
----- Original Message -----
From: "Dr. Evil" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, October 20, 2001 6:11 AM
Subject: The simplest possible way of logging to a file from Tomcat 4?


>
> Hi, I have a question for the log4j users:
>
> I am trying to do something which seems like it should be simple, but
> I can't figure out how to do it.  I want to be able to put things in
> my code that look something like this:
>
> Log.add("About to call this method...");
>
> and have the string "About to call this method..." show up in a file
> somewhere.  This is all from Tomcat 4.  Is there a way to do this from
> log4j?  It seems like it should be a simple way to do it, but there is
> nothing like that in the documentation.  I can see a way to get it to
> log to a Writer, but then that means that in every single class that I
> create, I have to put in code for creating and managing a Writer,
> which means reading config files to find out the filename to use, etc,
> etc, all of which could cause exceptions, which basically defeats the
> purpose of a logger, right?
>
> I just want something which is the simplest possible way to write a
> string to a file.
>
> Thanks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to