• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

sorry bout this: log4j & tomcat question...

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Javaranchers,

Sorry about this but I've another post about setting up log4j1.2.8 on tomcat 5.5.9. I've had a look at previous posts but am still confused.

A few simple questions (and hopefully answers) should help me:

1) I have put log4j1.2.8.jar and commons-logging.jar into both CATALINA_HOME\common\lib and the WEB-INF\lib directory of my webapp. Is this all I need?

2)Does my CATALINA_HOME\common\classes directory need anything more than the log4j.properties file that comes with apache? This file is for tomcat itself, right? Not my individual app?

3) The backing java code (my app is a simple javaserver faces one) runs when I request the jsp page using a web browser. the code that runs is:

org.apache.log4j.xml.DOMConfigurator.configure("C:\\log4j.xml");

Should I specify an absolute filepath as I have done or one relevant to my app root? I think what I'm doing actually works because I get no message in the tomcat logs saying log4j was not set up correctly, however...

4) The java code then attempts to do this:
Logger logger = Logger.getLogger(this.getClass());
logger.info("JS$ This is a test info log message:" + System.currentTimeMillis());

Again no exception is thrown but my log message DOES NOT APPEAR anywhere!! nor is a log file created.

Here is the actual config file located at C:\log4j.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

<appender name="appender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:\logfile.txt"/>

<!-- Change the next value to true to prevent log file overwrite -->
<param name="Append" value="false"/>
<param name="MaxFileSize" value="100MB"/>
<param name="MaxBackupIndex" value="2"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %p %l- %m%n"/>
</layout>
</appender>

<root>
<!-- Adjust Log Level on next line -->
<priority value ="info"/>
<appender-ref ref="appender"/>
</root>

</log4j:configuration>

I'm sure I'm doing something wrong. It seems very odd to me to specify absolute file paths in a) the call to tell DOMConfigurator where the log4j.xml file is and b) the <param name="File" value="C:\logfile.txt"/> attribute in the xml config file.

Could anyone see what I'm doing wrong. I have tried playing round with this for over a day now to no avail... :0(

I'd very much appreciate some help.
Regards,
John
 
John Summers
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok ok i admit i was too long winded. here is the abbreviated post:

For application level log4j logging, if i put my log4j.xml file in app_root/WEB-INF/classes/ do I still need to call DomConfigurator.configure("filename") and if so, what filepath do I pass to this call? Relative or absolute?

In my log4j.xml file, when I specify the target log file location do i put a relative or absolute filepath?

thanks
john
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!