File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Odd validation error in log4j.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Odd validation error in log4j.xml" Watch "Odd validation error in log4j.xml" New topic
Author

Odd validation error in log4j.xml

Austin Shelton
Greenhorn

Joined: Jul 01, 2010
Posts: 11
My 64-bit Eclipse running on Windows with Tomcat 7.0 is getting bent out about of shae. It's claiming that the following is missing well-formed elements after the "log4j:configuration" line. Any tips welcome. Thanks.

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

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="webapp" version="3.0"/>

<log4j:configuration>
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n"/>
</layout>
</appender>

<ajs.HWServlet>
<priority value="debug"/>
<appender-ref ref="stdout"/>
</ajs.HWServlet>

<root>
<priority value="debug"/>
<appender-ref ref="stdout"/>
</root>
</log4j:configuration>

</web-app>


Austin Shelton
ashelton3@gmail.com
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

What is the log4j configuration doing in your web application deployment descriptor ? Shouldn't it be in its own log4j.xml ?


[My Blog]
All roads lead to JavaRanch
Austin Shelton
Greenhorn

Joined: Jul 01, 2010
Posts: 11
My log4j.xml file is both in my WebContent section of my Eclipse workbench and synchronized with an external file. Changes I make in Eclipse are automatically reflected in the external file. I use an static string to point to the log4j.xml file which I change when deployment time rolls around.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

It doesn't explain what log4j:configuration is doing in the web-app tag of your web.xml. That's web.xml that you have pasted here, isn't it ?
Austin Shelton
Greenhorn

Joined: Jul 01, 2010
Posts: 11
This is a log4j.xml file and has nothing to do with my web.xml file. I'm sorry if I didn't make that clear before. BTW, not having the "web-app" declaration causes other errors in Eclipse (which I cannot unfortunately remember now). In any event, the "web-app" declaration should do no harm. The problem is with the incomprehensible message that the log4j:configuration tag produces. It looks like all my tags contained therein are correctly well-formed. I guess I need another set of eyes to look at it and offer opinions on the whole in general.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

In any event, the "web-app" declaration should do no harm.

If has nothing to do here. Remove it And fix those errors first.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137
    
  21

Whether stuffing in an unrelated element to an XML file "does no harm" depends entirely on how the XML is parsed and processed. Anything could happen, right up to and including crashing the entire application.

You didn't quote the error message, but the implication is that the Log4J xml parser is at that web.xml.

Making an IDE happy is a very bad reason for building invalid config files.


Customer surveys are for companies who didn't pay proper attention to begin with.
Austin Shelton
Greenhorn

Joined: Jul 01, 2010
Posts: 11
Good points. I'll try removing the web-app declaration and see what that does.
Austin Shelton
Greenhorn

Joined: Jul 01, 2010
Posts: 11
Hi,

Problem solved. I removed the "web-app" declaration at the beginning of my log4j.xml file and corrected the markup inside of it:

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

<log4j:configuration>
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n"/>
</layout>
</appender>

<logger name="ajs.HWServlet">
<level value="debug"/>
<appender-ref ref="stdout"/>
</logger>

<root>
<priority value="debug"/>
<appender-ref ref="stdout"/>
</root>
</log4j:configuration>
 
Consider Paul's rocket mass heater.
 
subject: Odd validation error in log4j.xml