Coverage Report - com.aragost.javahg.log.LoggerFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
LoggerFactory
81%
9/11
N/A
1
 
 1  
 package com.aragost.javahg.log;
 2  
 
 3  
 import com.aragost.javahg.internals.ServiceLoader;
 4  
 import com.google.common.base.Strings;
 5  
 
 6  
 /**
 7  
  * Factory class to retrieve a {@link Logger} instance. The LoggerFactory 
 8  
  * searches a implementation with the use of {@link ServiceLoader}, if no
 9  
  * implementation could be found it uses the default implementation 
 10  
  * {@link JULLoggerFactory}.
 11  
  */
 12  1
 public abstract class LoggerFactory {
 13  
 
 14  
     private static LoggerFactory instance;
 15  
   
 16  
     static {
 17  1
         String loggerFactoryName = System.getProperty( LoggerFactory.class.getName() );
 18  
         try 
 19  
         {
 20  1
             if ( ! Strings.isNullOrEmpty(loggerFactoryName) ){
 21  0
                 instance = (LoggerFactory) Class.forName(loggerFactoryName).newInstance();
 22  
             } else {
 23  1
                 instance = ServiceLoader.loadService(LoggerFactory.class);
 24  
             }
 25  
         } 
 26  0
         catch (Exception ex)
 27  
         {
 28  
           // do nothing
 29  1
         }
 30  1
         if ( instance == null ){
 31  1
             instance = new JULLoggerFactory();
 32  
         }
 33  1
     }
 34  
   
 35  
     /**
 36  
      * Return a logger for the class
 37  
      * 
 38  
      * @param cls
 39  
      * @return
 40  
      */
 41  
     public static Logger getLogger(Class<?> cls) {
 42  8
         return instance.getLoggerInstance(cls);
 43  
     }
 44  
     
 45  
     protected abstract Logger getLoggerInstance(Class<?> cls);
 46  
 
 47  
 }