commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Florian Kiebel" <>
Subject RE: configuring Logging
Date Wed, 02 Jun 2004 16:58:23 GMT

So is a text file which contains all the config for log4j
with logger and appenders...
Like this file (Be careful it's for a webapp...):
# Définition des Logger "log4j.logger." + nom de la classe + " = " + level +
nom du logger
# log4j.rootLogger=debug, stdout, R = debug, Runtime
log4j.logger.CRON = debug, CRON

# log4j.appender.stdout=org.apache.log4j.ConsoleAppender
# log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
# log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

# Keep one backup file

log4j.appender.Runtime.layout.ConversionPattern=%p %t %c - %m%n

# Keep one backup file

log4j.appender.CRON.layout.ConversionPattern=%p %t %c - %m%n

So as an example, you have a logger "log4j.logger.CRON = debug, CRON" so
CRON is a java class in this class I created an instance of a Logger object
called CRON. As you can see in the line before, I have put the priority to
Debug level.
In my CRON class, I have "Logger cronLog = Logger.getLogger("CRON");"
This is a reference towards my logger definition in

Then I define an appender with the lines "log4j.appender.CRON ..."
This appender permits to send log messages in the target here a
RollingFileAppender (file with daily save) named cron.log 

I define also a format of log messages with the two last lines (layout)
All of this is detailed in the doc of log4j Home and the excellent "short
introduction" of Ceki Gülcü and I have another link for you if you want :
which is a good demo of log4j

All I do is for a webapp which needs an initialization of log4j by a
servlet, I give you the init() method:
public void init() {
		String prefix =  getServletContext().getRealPath("/");
		String file = getInitParameter("log4j-init-file");
		// if the log4j-init-file is not set, then no point in
		if(file != null) {
Int this, you see "log4j-init-file" which points towards in
the web.xml of my webapp, don't forget to import the packages and to put
them in your classpath.

You can set a xml config file and at this point you must change
PropertyConfigurator as DOMConfigurator

I hope I help you

Florian Kiebel

-----Message d'origine-----
De : Ashish Naik [] 
Envoyé : mercredi 2 juin 2004 18:06
À : Jakarta Commons Users List
Objet : RE: configuring Logging

Its not a web application. I donot understand how the properties are set
e.g. as mentioned in the user guide. Is
it to configure Log4J?

Ashish Naik

-----Original Message-----
From: Jose Antonio Perez Testa []
Sent: 02 June 2004 16:59
To: Jakarta Commons Users List
Subject: Re: configuring Logging

Hi Ashish,
If it is a WebApp, both log4j and commons-logging jars must be in

Ashish Naik wrote:

>I am not able to understand how to confifigure Log4J for Commons logging
>I have added log4j.jar to my classpath. How do I set
>I am refering to Logging User Guide at
>Ashish Naik
>This message (including any attachments) contains
>confidential information intended for a specific
>individual and purpose, and is protected by law.
>If you are not the intended recipient, you should
>delete this message and are hereby notified that
>any disclosure, copying, or distribution of this
>message, or the taking of any action based on it,
>is strictly prohibited.
>Visit us at
Este correo electrsnico y, en su caso, cualquier fichero anexo al mismo,
contiene informacisn de caracter confidencial exclusivamente dirigida a su
destinatario o destinatarios. Queda prohibida su divulgacisn, copia o
distribucisn a terceros sin la previa autorizacisn escrita de Indra. En el
caso de haber recibido este correo electrsnico por error, se ruega notificar
inmediatamente esta circunstancia mediante reenvmo a la direccisn
electrsnica del remitente.

The information in this e-mail and in any attachments is confidential and
solely for the attention and use of the named addressee(s). You are hereby
notified that any dissemination, distribution or copy of this communication
is prohibited without the prior written consent of Indra. If you have
received this communication in error, please, notify the sender by reply

To unsubscribe, e-mail:
For additional commands, e-mail:


This message (including any attachments) contains 
confidential information intended for a specific 
individual and purpose, and is protected by law. 
If you are not the intended recipient, you should 
delete this message and are hereby notified that 
any disclosure, copying, or distribution of this
message, or the taking of any action based on it, 
is strictly prohibited.

Visit us at

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message