logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stadelmann Josef" <josef.stadelm...@axa-winterthur.ch>
Subject AW: Re: Verification of log4j configuration file
Date Tue, 09 Aug 2011 09:56:30 GMT
Hi Antonio

I suggest to you the following. 
1. Take NetBeans or any other IDE and catch the log4j open sources as a project.
2. Build log4j yourself, 
3. JDK 6.0,  maven 2.2.1 and ant 1.7 and a few other lesser important things is all you need
4. Do BUILD using NetBeans. / you can use also from a dos window mvn install comand
5. Select build.xml and ask for the javadoc ANT target to get doc and API's built
6. Then start your TrowableProperty or DOMConfiguratir development

basically you have to consider a few Configurators

	Is extended by the 
			PropertyConfigurator		(reading config data from a property file)
			DOMConfigurator		(reading config data from a XML file)
				Either of the two can be extended by your own 

You may develop your own TrowablePropertyConfigurator or TrowableDOMConfigurator and engage
it as shown in the Java Class below but this time inside a try catch block.

So where is your TrowablePropertyConfigurator engaged?

Look at the file Log4JTest.java written by ThomasFenner under
./contribs/ThomasFenner  (here included as reference) 

You can see that this test catches exceptions if drives are not installed? OK?
And you can see which and how the PropertyConfigurator is engaged?

Now, at this stage we would engage your own TrowablePropertyConfigurator or your own TrowableDOMConfigurator

import org.apache.log4j.*;
import java.sql.*;
import java.lang.*;
import java.util.*;

public class Log4JTest
	// Create a category instance for this class
   static Category cat = Category.getInstance(Log4JTest.class.getName());

   public static void main(String[] args)
      // Ensure to have all necessary drivers installed !
			Driver d = (Driver)(Class.forName("oracle.jdbc.driver.OracleDriver").newInstance());
      catch(Exception e){}

      // Set the priority which messages have to be logged

		// Configuration with configuration-file
      catch(Exception e){}	

      // These messages with Priority >= setted priority will be logged to the database.
  		cat.debug("debug");  //this not, because Priority DEBUG is less than INFO

For further understanding:
Go to the ./docs/api/org(apache/log4j/PropertyConfigurator.html
Open this and study what the PropertyConfigurator does for you?
And you will find you confirmed that no exceptions are raise by log4j's PropertyConfigurator
for whatever reason. 
Can you extend the PropertyConfigurator and extend and implement TrowablePropertyConfigurator
! Certainly you can.

Finally do not forget to ask somebody from the developers group to help you check in your
working/tested source code.

Maybe somebody more know to the subject can comment my suggestions


-----Urspr√ľngliche Nachricht-----
Von: Antonio Rodriges [mailto:antonio.rrz@gmail.com] 
Gesendet: Montag, 8. August 2011 11:05
An: log4j-user@logging.apache.org
Betreff: Re: Re: Verification of log4j configuration file

Thank you, Josef,

however I would like to force log4j return me an error code or throw
an exception (however docs says it never throws anything) in case of a
malformed config file to stop my application. Otherwise all logs will
cause exceptions and will not appear anywhere.
What is the best practice for an application to behave in case of
malformed log4j conf file?

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

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

View raw message