logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ashraf Fouad" <ashraf_fo...@rayasoftware.com>
Subject Problem in initialization
Date Fri, 11 Apr 2003 21:12:41 GMT

I have posted before that I'm getting problem in reading properties file for log4j, as log4j
was not reading my properties file wherever I put it. I wrote the following code in my all
classes for initializating log4J using the absolute path of the properties file, by first
searching for the file in my classpath then pass it through Log4J:

public class xyz 
{

    // Define a static logger variable
    static Logger s_Logger = Logger.getLogger( xyz.class );

	//	Configure the logger 
    static {
        URL l_Url = ClassLoader.getSystemClassLoader().getResource( LOG4J_FILE );
        PropertyConfigurator.configureAndWatch( l_Url.getFile(),
        							LOG4J_DELAY );
    }
	...
	...
}

where LOG4J_FILE is defined as "/properties/sps_log4j.properties"
and LOG4J_DELAY us defined as 3600000

Environment:
*	My application runs as a web application & part of it runs as a daemon in the background
process as Java Application.
*	I use IBM WebSphere Studio Application Developer 4.0.3 in developing my application.
*	My folder hierarchy is as follows:
*	JSP on the root
*	WEB-INF directory containing web.xml file
*	/WEB-INF/classes/properties/sps_log4j.properties
*	/WEB-INF/lib/log4j-1.2.8.jar
*	For sure when I run the web application the IBM WebSphere test envoironment have classes
folder in my classpath.
*	Also when I run the Java Application, I make sure that the above directory is in my classpath
settings.
*	My sps_log4j.properties contains the following:
	# Set root logger level to ALL
	log4j.rootLogger=ALL, A1, A2

	# Begin specifying the appenders
	log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
	log4j.appender.A1.File=d:\\temp\\sps_log.txt
	log4j.appender.A1.DatePattern='.'yyyy-MM-dd
	log4j.appender.A1.layout=org.apache.log4j.PatternLayout
	log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS}%-4r [%t] %-5p %c %x - %m%n

	log4j.appender.A2=org.apache.log4j.ConsoleAppender
	log4j.appender.A2.layout=org.apache.log4j.PatternLayout
	log4j.appender.A2.layout.ConversionPattern=%d{HH:mm:ss,SSS}%-4r [%t] %-5p %c %x - %m%n

So where is the problem?
When I run the part of the application that runs as a batch process the code runs smoothly
without any problem at all, logging was working perfect.
But when I run the web application, the following error occurs:

l_Url comes to null, so PropertyConfigurator.configureAndWatch method throws ExceptionInInitializerError

So I replaced the part in the static initializer with
    static {
        PropertyConfigurator.configureAndWatch( LOG4J_FILE,
        							LOG4J_DELAY );
    }
and when I run the web application it passes this line successfully, but with the first line
calling s_Logger.info( "any text here" ) is not logged and the following warning in console
is written:
log4j:WARN No appenders could be found for logger (com.rsw.gaeb.sps.cache.xyz).
log4j:WARN Please initialize the log4j system properly.

Sorry for this long mail, but I had to describe all my problem & environmant because I
read lots about that problem in the mail archive and I know what will be the replies about
setting classpath, ..... lots of things.

so plz any help as I like Log4J a lot and I want to use it in my logging instead of my old
custom made logging tool I made from over a year & half.

Thankx

Ashraf Fouad Ayoub
Senior Developer
Raya Software

1 Abdel Hameed Lotfy St.,
Nasr City, Cairo 11371, Egypt
Phone:	*	(202) 670-3301/2/3/4/6/8 Ext. 295
Fax:	*	(202) 670-3296
Email:	* ashraf_fouad@rayasoftware.com
Web:     * http://www.rayasoftware.com/


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


Mime
View raw message