View Javadoc

1   package org.naftulin.logwrapper;
2   
3   /***
4    * Supports log4j and standard java logging.
5    * Since this package has to be stand alone I have to support both log4j,
6    * since it's used on majority of the projects I've worked on and java 
7    * standard logging if log4j is not present.
8    * Follows GOF adapter pattern.
9    *  
10   * @author henry naftulin
11   * @version 1.0
12   */
13  public abstract class LogAdapter {
14  	private static Boolean log4jLoggerInThePath = null;
15  	/***
16  	 * Retruns either Log4J logger or Java logger. If log4j logger can be found,
17  	 * preferes log4j over java.
18  	 */
19  	public static synchronized LogAdapter getLogger(Class clazz) {
20  		if (log4jLoggerInThePath == null) {
21  			try {
22  				Class.forName("org.apache.log4j.Logger");
23  				log4jLoggerInThePath = Boolean.TRUE;			
24  			} catch(ClassNotFoundException e) {
25  				log4jLoggerInThePath = Boolean.FALSE;
26  			}
27  		}
28  		if (Boolean.TRUE.equals(log4jLoggerInThePath)) {
29  			return new Log4JLogAdapter(clazz);
30  		}
31  		return new JDKLogAdapter(clazz);			
32  	}
33  	
34  	
35  	public abstract void log(LogLevelAdaptor level,String message);
36  	public abstract void log(LogLevelAdaptor level,String message, Throwable t);
37  }