commons-user mailing list archives

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

So log4j.properties 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
log4j.logger.org.apache.jsp.testRuntime_jsp = 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

log4j.appender.Runtime=org.apache.log4j.RollingFileAppender
log4j.appender.Runtime.File=c:/example.log
log4j.appender.Runtime.MaxFileSize=100KB
# Keep one backup file
log4j.appender.Runtime.MaxBackupIndex=1

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


log4j.appender.CRON=org.apache.log4j.RollingFileAppender
log4j.appender.CRON.File=c:/cron.log
log4j.appender.CRON.MaxFileSize=100KB
# Keep one backup file
log4j.appender.CRON.MaxBackupIndex=1

log4j.appender.CRON.layout=org.apache.log4j.PatternLayout
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 log4j.properties

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 :
http://www.vipan.com/htdocs/log4jhelp.html
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
trying
		if(file != null) {
			PropertyConfigurator.configure(prefix+file);
		}
	}
Int this, you see "log4j-init-file" which points towards log4j.properties 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 [mailto:ashishn@mahindrabt.com] 
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. log4j.configuration=log4j.properties as mentioned in the user guide. Is
it to configure Log4J?

Cheers,
Ashish Naik


-----Original Message-----
From: Jose Antonio Perez Testa [mailto:japtesta@indra.es]
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
WEB-INF/lib


Ashish Naik wrote:

>I am not able to understand how to confifigure Log4J for Commons logging
>API.
>
>I have added log4j.jar to my classpath. How do I set
>log4j.configuration=log4j.properties
>
>I am refering to Logging User Guide at
>http://jakarta.apache.org/commons/logging/guide.html
>
>
>Cheers,
>Ashish Naik
>
>
>*********************************************************
>Disclaimer:
>
>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 http://www.mahindrabt.com
>
>
>
----------------------------------------------------------------------------
---------------------------------------
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
e-mail

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org



*********************************************************
Disclaimer:          

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 http://www.mahindrabt.com


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message