Hello Peter,

Well, here's an example that I added to the open source Barracuda project (
http://barracuda.enhydra.org/ ).  I'm attaching a zip file that
includes the web.xml and the Log4jInit servlet that the Barracuda
project uses.  The nice thing with this servlet is that is sets up
Log4j using configureAndWatch() if it is able to use an absolute file
path (ie... it isn't working straight out of a .war file, rather it is
running from a directory on the file system).  If it is running from a
.war file, it loads it via URL...and if it can't find the file in the
specified location, it just lets Log4j set itself up (assuming you put
log4j.properties or log4j.xml in WEB-INF/classes).

Hope this helps,

P.S.  If you want to see the example working, go grab the latest cvs from
the Baracuda project, build, and set up Barracuda with Tomcat.

Jake

Wednesday, June 05, 2002, 8:58:25 AM, you wrote:

PC> i followed the instruction from the log4j documentation and put in my 
PC> web.xml file the following for the servlet:


PC>      <servlet>
PC>        <servlet-name>TallyTeset</servlet-name>
PC>        <servlet-class>roster.TallyTest</servlet-class>
PC>        <init-param>
PC>           <param-name>log4j-init-file</param-name>
PC>           <param-value>WEB-INF/classes/roster/log4j-ct.prop</param-value>
PC>        </init-param>
PC>        <load-on-startup>1</load-on-startup>
PC>      </servlet>

PC> and i use the following code to read the properties file:

PC>          public void init(ServletConfig config) throws ServletException{
PC>                  super.init(config);
PC>                  prefix = getServletContext().getRealPath("/");
PC>                  file = getInitParameter("log4j-init-file");
PC>                  System.out.println("Prefix: " + prefix);
PC>                  System.out.println("File: " + file);
PC>          }

PC> put looking at it the getInitParameter() method isn't reading the 
PC> initialization from the web.xml.  is that correct?  i thought it would read 
PC> it from the web.xml file.

PC> At 09:48 AM 6/5/2002, Ted Velkoff wrote:
>>The problem is not in the property file, but rather that the servlet doesn't
>>know where to find the property file.
>>
>>There are two parts - making sure the servlet reads the file, and second,
>>telling the servlet where to look.
>>
>>1) This tells the configurator to read the property file when the servlet is
>>started
>>
>>public init() {
>>   ...
>>   PropertyConfigurator.configure(filename);
>>   ...
>>}
>>
>>2) But where does filename come from?  This can be a headache, but one
>>solution is to put it relative to some location you can easily find from
>>your servlet container.  In websphere, there's a system property
>>"server.root".  Either the same exists for Tomcat or something similar.
>>Anyway...
>>
>>public init() {
>>   ...
>>   String filename = System.getProperty("server.root") + File.separator +
>>"log.properties"
>>   ...  // where "log.properties" is the name of your log4j property file.
>>   ...  // of course you could have some intermediate directories under
>>server.root...
>>   PropertyConfigurator.configure(filename);
>>   ...
>>}
>>
>>
>>
>>
>>-----Original Message-----
>>From: Peter Choe [mailto:[EMAIL PROTECTED]]
>>Sent: Wednesday, June 05, 2002 9:31 AM
>>To: [EMAIL PROTECTED]
>>Subject: logger not working with servlet
>>
>>
>>i am trying to log4j to work with a servlet on tomcat4.0 and java1.4 on a
>>solaris intel machine.  but when i try to call the servlet to get it to
>>log, i get the following message:
>>
>>log4j:WARN No appenders could be found for logger (roster.TallyTest).
>>log4j:WARN Please initialize the log4j system properly.
>>
>>this is my log property file:
>>
>>log4j.rootLogger=debug, A1, R
>>
>>log4j.appender.A1=org.apache.log4j.ConsoleAppender
>>
>>log4j.appender.A1.layout=org.apache.log4j.PatternLayout
>>log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
>>
>>log4j.appender.R=org.apache.log4j.RollingFileAppender
>>log4j.appender.R.File=/export/home/tomcat/logs/coursetally.log
>>log4j.appender.R.MaxFileSize=100KB
>>log4j.appender.R.MaxBackupIndex=1
>>
>>log4j.appender.R.layout=org.apache.log4j.PatternLayout
>>log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
>>~
>>
>>any suggestions on why it isn't working for my servlets, but works for
>>stand alone java applications?
>>
>>Peter Choe
>>
>>
>>--
>>To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
>>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

PC> Peter Choe


PC> --
PC> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
PC> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>



-- 
Best regards,
 Jacob                            mailto:[EMAIL PROTECTED]

Attachment: log4jinit.zip
Description: Zip compressed data

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

Reply via email to