Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

Trace.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Emmanuel Cecchet.
00022  * Contributor(s): __________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.common.log;
00026 
00027 import org.apache.log4j.Logger;
00028 import org.apache.log4j.Priority;
00029 
00030 /**
00031  * This a wrapper to the log4j logging system. We provide additional features
00032  * to statically remove tracing.
00033  * 
00034  * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet</a>
00035  * @version 1.0
00036  */
00037 public class Trace
00038 {
00039   /** Log4j logger instance. */
00040   private Logger log4jLogger;
00041 
00042   /**
00043    * Creates a new <code>Trace</code> object from a given log4j <code>Logger</code>.
00044    * 
00045    * @param log4jLogger the log4j <code>Logger</code>
00046    */
00047   protected Trace(Logger log4jLogger)
00048   {
00049     this.log4jLogger = log4jLogger;
00050   }
00051 
00052   /**
00053    * Retrieves a logger by its name.
00054    * 
00055    * @param name logger name
00056    * @return trace a <code>Trace</code> instance
00057    */
00058   public static Trace getLogger(String name)
00059   {
00060     return LogManager.getLogger(name);
00061   }
00062 
00063   /**
00064    * Logs a message object with the <code>DEBUG</code> <code>Level</code>.
00065    * 
00066    * @param message the message object to log
00067    */
00068   public void debug(Object message)
00069   {
00070     log4jLogger.debug(message);
00071   }
00072 
00073   /**
00074    * Logs a message object with the <code>DEBUG</code> <code>Level</code>
00075    * including the stack trace of the {@link Throwable}<code>error</code>
00076    * passed as parameter.
00077    * 
00078    * @param message the message object to log
00079    * @param error the exception to log, including its stack trace
00080    */
00081   public void debug(Object message, Throwable error)
00082   {
00083     log4jLogger.debug(message, error);
00084   }
00085 
00086   /**
00087    * Logs a message object with the <code>ERROR</code> <code>Level</code>.
00088    * 
00089    * @param message the message object to log
00090    */
00091   public void error(Object message)
00092   {
00093     log4jLogger.error(message);
00094   }
00095 
00096   /**
00097    * Logs a message object with the <code>ERROR</code> <code>Level</code>
00098    * including the stack trace of the {@link Throwable}<code>error</code>
00099    * passed as parameter.
00100    * 
00101    * @param message the message object to log.
00102    * @param error the exception to log, including its stack trace.
00103    */
00104   public void error(Object message, Throwable error)
00105   {
00106     log4jLogger.error(message, error);
00107   }
00108 
00109   /**
00110    * Logs a message object with the <code>FATAL</code> <code>Level</code>.
00111    * 
00112    * @param message the message object to log.
00113    */
00114   public void fatal(Object message)
00115   {
00116     log4jLogger.fatal(message);
00117   }
00118 
00119   /**
00120    * Logs a message object with the <code>FATAL</code> <code>Level</code>
00121    * including the stack trace of the {@link Throwable}<code>error</code>
00122    * passed as parameter.
00123    * 
00124    * @param message the message object to log.
00125    * @param error the exception to log, including its stack trace.
00126    */
00127   public void fatal(Object message, Throwable error)
00128   {
00129     log4jLogger.fatal(message, error);
00130   }
00131 
00132   /**
00133    * Logs a message object with the <code>INFO</code> <code>Level</code>.
00134    * 
00135    * @param message the message object to log.
00136    */
00137   public void info(Object message)
00138   {
00139     log4jLogger.info(message);
00140   }
00141 
00142   /**
00143    * Logs a message object with the <code>INFO</code> <code>Level</code>
00144    * including the stack trace of the {@link Throwable}<code>error</code>
00145    * passed as parameter.
00146    * 
00147    * @param message the message object to log.
00148    * @param error the exception to log, including its stack trace.
00149    */
00150   public void info(Object message, Throwable error)
00151   {
00152     log4jLogger.info(message, error);
00153   }
00154 
00155   /**
00156    * Logs a message object with the <code>WARN</code> <code>Level</code>.
00157    * 
00158    * @param message the message object to log.
00159    */
00160   public void warn(Object message)
00161   {
00162     log4jLogger.warn(message);
00163   }
00164 
00165   /**
00166    * Logs a message object with the <code>WARN</code> <code>Level</code>
00167    * including the stack trace of the {@link Throwable}<code>error</code>
00168    * passed as parameter.
00169    * 
00170    * @param message the message object to log.
00171    * @param error the exception to log, including its stack trace.
00172    */
00173   public void warn(Object message, Throwable error)
00174   {
00175     log4jLogger.warn(message, error);
00176   }
00177 
00178   /**
00179    * Checks whether this category is enabled for the <code>DEBUG</code> <code>Level</code>.
00180    * 
00181    * <p>
00182    * This function is intended to lessen the computational cost of disabled log
00183    * debug statements.
00184    * 
00185    * <p>
00186    * For some <code>cat</code> Category object, when you write,
00187    * 
00188    * <pre>
00189    *  cat.debug("This is entry number: " + i );
00190    * </pre>
00191    * 
00192    * 
00193    * <p>
00194    * You incur the cost constructing the message, concatenatiion in this case,
00195    * regardless of whether the message is logged or not.
00196    * 
00197    * <p>
00198    * If you are worried about speed, then you should write
00199    * 
00200    * <pre>
00201    *  if(cat.isDebugEnabled()) { cat.debug("This is entry number: " + i ); }
00202    * </pre>
00203    * 
00204    * 
00205    * <p>
00206    * This way you will not incur the cost of parameter construction if
00207    * debugging is disabled for <code>cat</code>. On the other hand, if the
00208    * <code>cat</code> is debug enabled, you will incur the cost of evaluating
00209    * whether the category is debug enabled twice. Once in <code>isDebugEnabled</code>
00210    * and once in the <code>debug</code>. This is an insignificant overhead
00211    * since evaluating a category takes about 1%% of the time it takes to
00212    * actually log.
00213    * 
00214    * @return <code>true</code> if this category is debug enabled, <code>false</code>
00215    *         otherwise.
00216    */
00217   public boolean isDebugEnabled()
00218   {
00219     return log4jLogger.isDebugEnabled();
00220   }
00221 
00222   /**
00223    * Checks whether this category is enabled for the <code>INFO</code>
00224    * <code>Level</code>.
00225    * See also {@link #isDebugEnabled}.
00226    * 
00227    * @return <code>true</code> if this category is enabled for <code>Level</code> <code>INFO</code>,
00228    *         <code>false</code> otherwise.
00229    */
00230   public boolean isInfoEnabled()
00231   {
00232     return log4jLogger.isInfoEnabled();
00233   }
00234 
00235   /**
00236    * Checks whether this category is enabled for the <code>INFO</code> 
00237    * <code>Level</code>.
00238    * See also {@link #isDebugEnabled}.
00239    * 
00240    * @return <code>true</code> if this category is enabled for <code>INFO</code> <code>Level</code>,
00241    *         <code>false</code> otherwise.
00242    */
00243   public boolean isWarnEnabled()
00244   {
00245     return log4jLogger.isEnabledFor(Priority.WARN);
00246   }
00247 
00248   /**
00249    * Checks whether this category is enabled for the <code>INFO</code>
00250    * <code>Level</code>.
00251    * See also {@link #isDebugEnabled}.
00252    * 
00253    * @return <code>true</code> if this category is enabled for <code>INFO</code> <code>Level</code>,
00254    *         <code>false</code> otherwise.
00255    */
00256   public boolean isErrorEnabled()
00257   {
00258     return log4jLogger.isEnabledFor(Priority.ERROR);
00259   }
00260 
00261   /**
00262    * Checks whether this category is enabled for the <code>INFO</code> 
00263    * <code>Level</code>.
00264    * See also {@link #isDebugEnabled}.
00265    * 
00266    * @return <code>true</code> if this category is enabled for <code>INFO</code> <code>Level</code>,
00267    *         <code>false</code> otherwise.
00268    */
00269   public boolean isFatalEnabled()
00270   {
00271     return log4jLogger.isEnabledFor(Priority.FATAL);
00272   }
00273 }

Generated on Mon Apr 11 22:01:35 2005 for C-JDBC by  doxygen 1.3.9.1