Two Laptop Bag*
The moose likes Tomcat and the fly likes sorry bout this: log4j & tomcat question... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "sorry bout this: log4j & tomcat question..." Watch "sorry bout this: log4j & tomcat question..." New topic
Author

sorry bout this: log4j & tomcat question...

John Summers
Ranch Hand

Joined: Oct 06, 2003
Posts: 125
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

Joined: Oct 06, 2003
Posts: 125
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: sorry bout this: log4j & tomcat question...