Coverage Report - net.admin4j.log.LogManagerRegistry
 
Classes in this File Line Coverage Branch Coverage Complexity
LogManagerRegistry
42%
12/28
N/A
1
 
 1  
 /*
 2  
  * This software is licensed under the Apache License, Version 2.0
 3  
  * (the "License") agreement; you may not use this file except in compliance with
 4  
  * the License.  You may obtain a copy of the License at
 5  
  *
 6  
  *      http://www.apache.org/licenses/LICENSE-2.0
 7  
  *
 8  
  * Unless required by applicable law or agreed to in writing, software
 9  
  * distributed under the License is distributed on an "AS IS" BASIS,
 10  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11  
  * See the License for the specific language governing permissions and
 12  
  * limitations under the License.
 13  
  */
 14  
 package net.admin4j.log;
 15  
 
 16  
 import java.util.HashSet;
 17  
 import java.util.Set;
 18  
 
 19  
 import net.admin4j.config.Admin4JConfiguration;
 20  
 
 21  
 import org.slf4j.Logger;
 22  
 import org.slf4j.LoggerFactory;
 23  
 
 24  
 /**
 25  
  * Provides all available LogManagers.
 26  
  *
 27  
  * @author D. Ashmore
 28  
  *
 29  
  */
 30  
 @SuppressWarnings("rawtypes")
 31  0
 public class LogManagerRegistry {
 32  
 
 33  12
         private static Logger logger = LoggerFactory.getLogger(LogManagerRegistry.class);
 34  12
         private static final Set<LogManager> availableLogManagerSet = new HashSet<LogManager>();
 35  
 
 36  
         static {
 37  
                 try {
 38  12
                         Class log4JLogManager = Class.forName("net.admin4j.log.Log4JLogManager");
 39  12
                         availableLogManagerSet.add((LogManager) log4JLogManager.newInstance());
 40  0
                 } catch (ClassNotFoundException e) {
 41  0
                         logger.info("Log4J Not Found in classpath -- Log4J exceptions not viewable within Admin4J.");
 42  0
                 } catch (Throwable e) {
 43  0
                         logger.warn("Error instantiating Log4JLogManager", e);
 44  12
                 }
 45  
 
 46  
                 try {
 47  12
                         Class logbackLogManager = Class.forName("net.admin4j.log.LogbackLogManagerV1_6");
 48  12
                         availableLogManagerSet.add((LogManager) logbackLogManager.newInstance());
 49  0
                 } catch (ClassNotFoundException e) {
 50  0
                         logger.info("Logback Not Found in classpath -- Logback exceptions not viewable within Admin4J.");
 51  0
                 } catch (Throwable e) {
 52  0
                         logger.warn("Error instantiating LogbackLogManagerV1_6", e);
 53  12
                 }
 54  
 
 55  12
                 availableLogManagerSet.add(new JdkLogManager());
 56  
 
 57  12
                 for (String logManagerClassName : Admin4JConfiguration.getAdditionalLogManagerClassNames()) {
 58  
                         try {
 59  0
                                 Class logManager = Class.forName(logManagerClassName);
 60  0
                                 availableLogManagerSet.add((LogManager) logManager.newInstance());
 61  0
                         } catch (ClassNotFoundException e) {
 62  0
                                 logger.info("Additional LogManager Not Found in classpath -- these exceptions not viewable within Admin4J.");
 63  0
                         } catch (Throwable e) {
 64  0
                                 logger.error("Error instantiating additional LogManager", e);
 65  0
                         }
 66  
                 }
 67  12
         }
 68  
 
 69  
         public static Set<LogManager> getAvailableLogManagerSet() {
 70  15
                 return availableLogManagerSet;
 71  
         }
 72  
 
 73  
 }