You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Emily Bache <em...@astrakan.se> on 2001/10/30 16:30:30 UTC

xml configuration file example

Hi,

I feel this information is probably out there somewhere, but I have looked
everywhere I can think of, so I'm turning to you for help! I basically just
want an example xml configuration file that works with the DOMConfigurator.
I've been using a PropertyConfigurator, and I'd like to use an xml file
instead. I don't know what format the DOMConfigurator expects, or how to
work it out. 

My properties file looks like this:

log4j.rootCategory=DEBUG, stdout , file
 
log4j.appender.stdout=org.apache.log4j.FileAppender
log4j.appender.stdout.File=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=ecore.log
log4j.appender.file.MaxFileSize=100KB
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

This is really simple - two appenders, one to standard output one to file.
Can anyone tell me what this would look like as an xml file suitable for the
DOMConfigurator?

Just to show I have done my homework and aren't just whining :-) I have
checked: 

** the javadoc for DOMConfigurator
	This just told me where the dtd is. Am I supposed to read this dtd
to find out the format the DOMConfigurator expects?

** the FAQ, which says:
	Is there example code for using log4j?
	There is a directory containing examples in org/log4j/examples. See
also 	org/log4j/xml/examples. 

	I couldn't these paths in the jar I downloaded, and I couldn't find
any sample xml files. 	What am I missing?

** the archive for this list. 
	I didn't seem to get any relevant hits when I searched. Someone else
with a similar problem helpfully said that they found the answer searching
the archives though. Shame he didn't post a reference to what he found...

Any help gratefully appreciated!

Emily Bache


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: xml configuration file example

Posted by Yoav Shapira <sh...@mpi.com>.
Howdy,
In the javadoc for DOMConfigurator, and also in the introductory manual,
there are links to XML files with very similar examples... But here
it is to make your life easier:

(See some comments after XML 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="stdout" class="org.apache.log4j.FileAppender">
           <layout class="org.apache.log4j.PatternLayout">
             <param name="ConversionPattern"
		    value="%-4r [%t] %-5p %c %x - %m %n" />
           </layout>	    
	</appender>

          
        <appender name="fileAppender"
class="org.apache.log4j.RollingFileAppender">
          <param name="File" value="ecore.log" />
          <param name="MaxFileSize" value="100KB" />
          <layout class="org.apache.log4j.PatternLayout"> 
            <param name="ConversionPattern"
                   value="%d [%t] %-5p %c - %m%n" />
          </layout>
        </appender>
	<root>
	   <level value ="debug" />
   	   <appender-ref ref="stdout" />
           <appender-ref ref="fileAppender" />
	</root>
	
</log4j:configuration>

Comments:
- Renamed appender "file" to "fileAppender" as file is a param name and
could be easily confused.

- Using log4j v1.2 syntax, e.g. level instead of priority for the root
category, simply because the above is taken from my config file and
I'm too lazy to convert back to 1.x syntax ;)

Hope this helps,

Yoav

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: xml configuration file example

Posted by Thomas Tuft Muller <tt...@online.no>.
Emily,

See http://jakarta.apache.org/log4j/docs/download.html

Log4j 1.1.3 is the last stable version, and it comes with source,
documentation, examples etc. XML examples can be found in
<log4j>src\java\org\apache\log4j\xml\examples.

Hope this helps.

--

Thomas


| -----Original Message-----
| From: Emily Bache [mailto:emily.bache@astrakan.se]
| Sent: 30 October 2001 15:31
| To: 'log4j-user@jakarta.apache.org'
| Subject: xml configuration file example
|
|
|
| Hi,
|
| I feel this information is probably out there somewhere, but I have looked
| everywhere I can think of, so I'm turning to you for help! I
| basically just
| want an example xml configuration file that works with the
| DOMConfigurator.
| I've been using a PropertyConfigurator, and I'd like to use an xml file
| instead. I don't know what format the DOMConfigurator expects, or how to
| work it out.
|
| My properties file looks like this:
|
| log4j.rootCategory=DEBUG, stdout , file
|
| log4j.appender.stdout=org.apache.log4j.FileAppender
| log4j.appender.stdout.File=System.out
| log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
| log4j.appender.stdout.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
|
| log4j.appender.file=org.apache.log4j.RollingFileAppender
| log4j.appender.file.File=ecore.log
| log4j.appender.file.MaxFileSize=100KB
| log4j.appender.file.layout=org.apache.log4j.PatternLayout
| log4j.appender.file.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
|
| This is really simple - two appenders, one to standard output one to file.
| Can anyone tell me what this would look like as an xml file
| suitable for the
| DOMConfigurator?
|
| Just to show I have done my homework and aren't just whining :-) I have
| checked:
|
| ** the javadoc for DOMConfigurator
| 	This just told me where the dtd is. Am I supposed to read this dtd
| to find out the format the DOMConfigurator expects?
|
| ** the FAQ, which says:
| 	Is there example code for using log4j?
| 	There is a directory containing examples in org/log4j/examples. See
| also 	org/log4j/xml/examples.
|
| 	I couldn't these paths in the jar I downloaded, and I couldn't find
| any sample xml files. 	What am I missing?
|
| ** the archive for this list.
| 	I didn't seem to get any relevant hits when I searched. Someone else
| with a similar problem helpfully said that they found the answer searching
| the archives though. Shame he didn't post a reference to what he found...
|
| Any help gratefully appreciated!
|
| Emily Bache
|
|
| --
| To unsubscribe, e-mail:
| <ma...@jakarta.apache.org>
| For additional commands, e-mail:
| <ma...@jakarta.apache.org>
|
|



*************************************************************************
Copyright ERA Technology Ltd. 2001. (www.era.co.uk). All rights reserved. 
Confidential. No liability whatsoever is accepted for any loss or damage 
suffered as a result of accessing this message or any attachments.

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>