aspose file tools*
The moose likes Other Open Source Projects and the fly likes log4j with xml config file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "log4j with xml config file" Watch "log4j with xml config file" New topic
Author

log4j with xml config file

Franz Degenhardt
Greenhorn

Joined: Jan 07, 2003
Posts: 12
This is my log4jproperties.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/' >
...
</log4j:configuration>
The logging works, but when I open the xml-file in IE6 I get the following error:
Reference to undeclared Namespace-Pr�fix: 'log4j'. line 3, column 1
I try several example files, but all produces the same error. I changed the log4j.dtd too.
Any Suggestions?
mfg Franz Degenhardt
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Moving to Open Source Projects.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Franz Degenhardt
Greenhorn

Joined: Jan 07, 2003
Posts: 12
Hi Folks!
I visited nearly every google result for log4j! I found several example config files. All produces the same error as above. The few that works doesnt implement the log4j.dtd, so no wonder that all works. I looked over the dtd too. All seams to be ok. So what is it? There are about 20 Mirrors off the log4j-api. All with broken links to examples!
Any other suggestions to get a working xml-config file including the dtd?
Franz Degenhardt
Kees van Oosterhout
Ranch Hand

Joined: Jul 08, 2002
Posts: 34
Have you tried placing the .dtd file in the same dir as your .xml file?


"...you've got to ask yourself one question, Do I feel lucky?"
Franz Degenhardt
Greenhorn

Joined: Jan 07, 2003
Posts: 12
Hello! Thanks for your answer.
It is atm. Otherwise I got: "cant find resource log4j.dtd"
I found several config-files in the internet, but those which produces no errors have the doctype statement missing. If I leave it out too, it works correkt. But thats not what I want, as you can imagine.
Franz Degenhardt
Kees van Oosterhout
Ranch Hand

Joined: Jul 08, 2002
Posts: 34
There is one thing. Be sure to place the .dtd file in the exactly the same directory as the config file and not in a subdirectory like 'org.apache....'. If it is, i can't help you...
(Try to download latest version of log4j. It is backwards compatible.... )
Franz Degenhardt
Greenhorn

Joined: Jan 07, 2003
Posts: 12
I made that sure. I downloaded an aktuell version, too. Same error as described above.
My configuration is working properly, but there is still the bug, that I cant view the config.xml in a browser like IE6.
Do you have a working config-file with a correct doctype-statement? I would be interressted.
Franz Degenhardt
Kees van Oosterhout
Ranch Hand

Joined: Jul 08, 2002
Posts: 34
My file:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="INFO" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="c:/logs/ecd/ecd_info.log" />
<param name="MaxFileSize" value="10240KB"/>
<param name="MaxBackupIndex" value="10" />
<param name="Append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyyMMdd HH:mm:ss} %-5p [%x] - %m%n"/>
<!--<param name="ConversionPattern" value="%d{yyyyMMdd HH:mm:ss} %-5p [%x] %C{1}.%M(%L) - %m%n"/> -->
</layout>
</appender>
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyyMMdd hh:mm:ss} %-5p [%x] %M(%C{1}:%L) - %m%n"/>
</layout>
</appender>
<root>
<priority value ="WARN" />
<appender-ref ref="INFO" />
</root>
</log4j:configuration>
Hope it helps...
Franz Degenhardt
Greenhorn

Joined: Jan 07, 2003
Posts: 12
Well, even with your file, I got still the same error:
Reference to undeclared namespacepr�fix: 'log4j'. line 3, position 1
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
^
Are you able to open your file in a browser without errors?
Franz Degenhardt
Kees van Oosterhout
Ranch Hand

Joined: Jul 08, 2002
Posts: 34
Yes, I do. I have IE6, the english version.
Kees van Oosterhout
Ranch Hand

Joined: Jul 08, 2002
Posts: 34
Franz, have you solved the problem yet?
Craig McDonald
Greenhorn

Joined: Jul 15, 2004
Posts: 1
Sorry this is kind of gigantic but here it is. This one works. In WSAD it does not like not having specific end tags on the Param lines. This also shows you how to do 2 output targets. I like logging to both a Socket for Chainsaw and to a file.

jens persson
Greenhorn

Joined: Aug 30, 2004
Posts: 1
Isn't the problem really that the log4j folks are using the namespaces in a strange way? The standard root element is log4j:configuration and the namespace for the log4j prefix is declared. But there is no declaration for the default empty namespace which all the other elements use. It seems strange. When I set the default namespace to the same namespace url the system still complains.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: log4j with xml config file