Coverage report

  %line %branch
net.sf.infrared.base.util.LoggerDecorator
12% 
100% 

 1  
 /* 
 2  
  * Copyright 2005 Tavant Technologies and Contributors
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License")
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  * 
 16  
  *
 17  
  *
 18  
  * Original Author:  kamal.govindraj (Tavant Technologies)
 19  
  * Contributor(s):   binil.thomas;
 20  
  *
 21  
  */
 22  
 package net.sf.infrared.base.util;
 23  
 
 24  
 import java.io.InputStream;
 25  
 import java.net.URL;
 26  
 import java.util.Enumeration;
 27  
 import java.util.Properties;
 28  
 import java.util.ResourceBundle;
 29  
 
 30  
 import org.apache.log4j.Appender;
 31  
 import org.apache.log4j.Level;
 32  
 import org.apache.log4j.Logger;
 33  
 import org.apache.log4j.Priority;
 34  
 import org.apache.log4j.spi.LoggerRepository;
 35  
 import org.apache.log4j.spi.LoggingEvent;
 36  
 import org.apache.log4j.xml.DOMConfigurator;
 37  
 
 38  
 /**
 39  
  * LoggingFactory implementation
 40  
  * 
 41  
  * @author kamal.govindraj
 42  
  * @author binil.thomas
 43  
  */
 44  
 public class LoggingFactory {
 45  
     public static final String DEBUG_KEY = "infrared.debug";
 46  
 
 47  
     public static final String INFO_KEY = "infrared.info";
 48  
 
 49  
     public static final String LOG4J_CONF = "infrared-log4j.xml";
 50  
     
 51  
     public static final String DEFAULT_CONF = "default-infrared-log4j.xml";
 52  
 
 53  
     private static URL log4jUrl = null;
 54  
     
 55  
     private static boolean isLoggingConfigured = false;
 56  
 
 57  
     private static boolean isUsingDefault = false;
 58  
     
 59  
     static {
 60  
         try {
 61  
             log4jUrl = Thread.currentThread().getContextClassLoader().getResource(LOG4J_CONF);
 62  
             if (log4jUrl == null) {
 63  
                 log4jUrl = Thread.currentThread().getContextClassLoader().getResource(DEFAULT_CONF);
 64  
                 isUsingDefault = true;
 65  
             }
 66  
             try {
 67  
                 Class.forName("net.sf.infrared.org.apache.log4j.LogManager");
 68  
             } catch (ClassNotFoundException ignored) {
 69  
             }
 70  
             DOMConfigurator.configure(log4jUrl);
 71  
             isLoggingConfigured = true;
 72  
         } catch (RuntimeException ex) {
 73  
             System.out.println("[InfraRED] Problems configuring logging system");
 74  
             ex.printStackTrace();
 75  
         }
 76  
     }
 77  
 
 78  
     public static Logger getLogger(Class clazz) {
 79  
         Logger wrapper = new LoggerDecorator(Logger.getLogger(clazz));
 80  
         return wrapper;
 81  
     }
 82  
 
 83  
     public static Logger getLogger(String loggerName) {
 84  
     	Logger wrapper = new LoggerDecorator(Logger.getLogger(loggerName));
 85  
         return wrapper;
 86  
     }
 87  
     
 88  
     public static URL getLoggingConfiguration() {
 89  
         return log4jUrl;
 90  
     }
 91  
     
 92  
     public static boolean isLoggingConfigured() {
 93  
         return isLoggingConfigured;
 94  
     }
 95  
     
 96  
     public static boolean isDefultLoggingUsed() {
 97  
         return isUsingDefault;
 98  
     }
 99  
     
 100  
     public static boolean isDebugLoggingEnabled() {
 101  
         return isInfoLoggingEnabled() || Boolean.getBoolean(LoggingFactory.DEBUG_KEY);
 102  
     }
 103  
 
 104  
     public static boolean isInfoLoggingEnabled() {
 105  
         return Boolean.getBoolean(LoggingFactory.INFO_KEY);
 106  
     }
 107  
 }
 108  
 
 109  
 class LoggerDecorator extends Logger {
 110  
 	private Logger delegate;
 111  
 	
 112  8
 	private static boolean debug = LoggingFactory.isDebugLoggingEnabled();
 113  
 
 114  8
     private static boolean info = LoggingFactory.isInfoLoggingEnabled();
 115  
 
 116  
 	public LoggerDecorator(Logger delegate) {
 117  19
 		super(delegate.getName());
 118  19
 		this.delegate = delegate;		
 119  19
 	}
 120  
 
 121  
 	public synchronized void addAppender(Appender arg0) {
 122  0
 		delegate.addAppender(arg0);		
 123  0
 	}
 124  
 
 125  
 	public void assertLog(boolean arg0, String arg1) {
 126  0
 		delegate.assertLog(arg0, arg1);
 127  0
 	}
 128  
 
 129  
 	public void callAppenders(LoggingEvent arg0) {
 130  0
 		delegate.callAppenders(arg0);
 131  0
 	}
 132  
 
 133  
 	public void debug(Object arg0, Throwable arg1) {
 134  0
 		delegate.debug(arg0, arg1);
 135  0
 	}
 136  
 
 137  
 	public void debug(Object arg0) {
 138  0
 		delegate.debug(arg0);
 139  0
 	}
 140  
 
 141  
 	public void error(Object arg0, Throwable arg1) {
 142  0
 		delegate.error(arg0, arg1);
 143  0
 	}
 144  
 
 145  
 	public void error(Object arg0) {
 146  2
 		delegate.error(arg0);
 147  2
 	}
 148  
 
 149  
 	public void fatal(Object arg0, Throwable arg1) {
 150  0
 		delegate.fatal(arg0, arg1);
 151  0
 	}
 152  
 
 153  
 	public void fatal(Object arg0) {
 154  0
 		delegate.fatal(arg0);
 155  0
 	}
 156  
 
 157  
 	public boolean getAdditivity() {
 158  0
 		return delegate.getAdditivity();
 159  
 	}
 160  
 
 161  
 	public synchronized Enumeration getAllAppenders() {
 162  0
 		return delegate.getAllAppenders();
 163  
 	}
 164  
 
 165  
 	public synchronized Appender getAppender(String arg0) {
 166  0
 		return delegate.getAppender(arg0);
 167  
 	}
 168  
 
 169  
 	public Priority getChainedPriority() {
 170  0
 		return delegate.getChainedPriority();
 171  
 	}
 172  
 
 173  
 	public Level getEffectiveLevel() {
 174  0
 		return delegate.getEffectiveLevel();
 175  
 	}
 176  
 
 177  
 	public LoggerRepository getHierarchy() {
 178  0
 		return delegate.getHierarchy();
 179  
 	}
 180  
 
 181  
 	public LoggerRepository getLoggerRepository() {
 182  0
 		return delegate.getLoggerRepository();
 183  
 	}
 184  
 
 185  
 	public ResourceBundle getResourceBundle() {
 186  0
 		return delegate.getResourceBundle();
 187  
 	}
 188  
 
 189  
 	public void info(Object arg0, Throwable arg1) {
 190  0
 		delegate.info(arg0, arg1);
 191  0
 	}
 192  
 
 193  
 	public void info(Object arg0) {
 194  0
 		delegate.info(arg0);
 195  0
 	}
 196  
 
 197  
 	public boolean isAttached(Appender arg0) {
 198  0
 		return delegate.isAttached(arg0);
 199  
 	}
 200  
 
 201  
 	public boolean isDebugEnabled() {
 202  96
 		return debug;
 203  
 	}
 204  
 
 205  
 	public boolean isEnabledFor(Priority arg0) {
 206  0
 		return delegate.isEnabledFor(arg0);
 207  
 	}
 208  
 
 209  
 	public boolean isInfoEnabled() {
 210  0
 		return info;
 211  
 	}
 212  
 
 213  
 	public void l7dlog(Priority arg0, String arg1, Object[] arg2, Throwable arg3) {
 214  0
 		delegate.l7dlog(arg0, arg1, arg2, arg3);
 215  0
 	}
 216  
 
 217  
 	public void l7dlog(Priority arg0, String arg1, Throwable arg2) {
 218  0
 		delegate.l7dlog(arg0, arg1, arg2);
 219  0
 	}
 220  
 
 221  
 	public void log(Priority arg0, Object arg1, Throwable arg2) {
 222  0
 		delegate.log(arg0, arg1, arg2);
 223  0
 	}
 224  
 
 225  
 	public void log(Priority arg0, Object arg1) {
 226  0
 		delegate.log(arg0, arg1);
 227  0
 	}
 228  
 
 229  
 	public void log(String arg0, Priority arg1, Object arg2, Throwable arg3) {
 230  0
 		delegate.log(arg0, arg1, arg2, arg3);
 231  0
 	}
 232  
 
 233  
 	public synchronized void removeAllAppenders() {
 234  0
 		delegate.removeAllAppenders();
 235  0
 	}
 236  
 
 237  
 	public synchronized void removeAppender(Appender arg0) {
 238  0
 		delegate.removeAppender(arg0);
 239  0
 	}
 240  
 
 241  
 	public synchronized void removeAppender(String arg0) {
 242  0
 		delegate.removeAppender(arg0);
 243  0
 	}
 244  
 
 245  
 	public void setAdditivity(boolean arg0) {
 246  0
 		delegate.setAdditivity(arg0);
 247  0
 	}
 248  
 
 249  
 	public void setLevel(Level arg0) {
 250  0
 		delegate.setLevel(arg0);
 251  0
 	}
 252  
 
 253  
 	public void setPriority(Priority arg0) {
 254  0
 		delegate.setPriority(arg0);
 255  0
 	}
 256  
 
 257  
 	public void setResourceBundle(ResourceBundle arg0) {
 258  0
 		delegate.setResourceBundle(arg0);
 259  0
 	}
 260  
 
 261  
 	public void warn(Object arg0, Throwable arg1) {
 262  0
 		delegate.warn(arg0, arg1);
 263  0
 	}
 264  
 
 265  
 	public void warn(Object arg0) {
 266  0
 		delegate.warn(arg0);
 267  0
 	}	
 268  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.