Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

log4j with xml config file

 
Franz Degenhardt
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Open Source Projects.
 
Franz Degenhardt
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried placing the .dtd file in the same dir as your .xml file?
 
Franz Degenhardt
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I do. I have IE6, the english version.
 
Kees van Oosterhout
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Franz, have you solved the problem yet?
 
Craig McDonald
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic