1. /*
  2. * Copyright 2001-2004 The Apache Software Foundation.
  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. package org.apache.commons.logging;
  17. /**
  18. * <p>A simple logging interface abstracting logging APIs. In order to be
  19. * instantiated successfully by {@link LogFactory}, classes that implement
  20. * this interface must have a constructor that takes a single String
  21. * parameter representing the "name" of this Log.</p>
  22. *
  23. * <p> The six logging levels used by <code>Log</code> are (in order):
  24. * <ol>
  25. * <li>trace (the least serious)</li>
  26. * <li>debug</li>
  27. * <li>info</li>
  28. * <li>warn</li>
  29. * <li>error</li>
  30. * <li>fatal (the most serious)</li>
  31. * </ol>
  32. * The mapping of these log levels to the concepts used by the underlying
  33. * logging system is implementation dependent.
  34. * The implemention should ensure, though, that this ordering behaves
  35. * as expected.</p>
  36. *
  37. * <p>Performance is often a logging concern.
  38. * By examining the appropriate property,
  39. * a component can avoid expensive operations (producing information
  40. * to be logged).</p>
  41. *
  42. * <p> For example,
  43. * <code><pre>
  44. * if (log.isDebugEnabled()) {
  45. * ... do something expensive ...
  46. * log.debug(theResult);
  47. * }
  48. * </pre></code>
  49. * </p>
  50. *
  51. * <p>Configuration of the underlying logging system will generally be done
  52. * external to the Logging APIs, through whatever mechanism is supported by
  53. * that system.</p>
  54. *
  55. * @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
  56. * @author Rod Waldhoff
  57. * @version $Id: Log.java,v 1.19 2004/06/06 21:16:04 rdonkin Exp $
  58. */
  59. public interface Log {
  60. // ----------------------------------------------------- Logging Properties
  61. /**
  62. * <p> Is debug logging currently enabled? </p>
  63. *
  64. * <p> Call this method to prevent having to perform expensive operations
  65. * (for example, <code>String</code> concatenation)
  66. * when the log level is more than debug. </p>
  67. */
  68. public boolean isDebugEnabled();
  69. /**
  70. * <p> Is error logging currently enabled? </p>
  71. *
  72. * <p> Call this method to prevent having to perform expensive operations
  73. * (for example, <code>String</code> concatenation)
  74. * when the log level is more than error. </p>
  75. */
  76. public boolean isErrorEnabled();
  77. /**
  78. * <p> Is fatal logging currently enabled? </p>
  79. *
  80. * <p> Call this method to prevent having to perform expensive operations
  81. * (for example, <code>String</code> concatenation)
  82. * when the log level is more than fatal. </p>
  83. */
  84. public boolean isFatalEnabled();
  85. /**
  86. * <p> Is info logging currently enabled? </p>
  87. *
  88. * <p> Call this method to prevent having to perform expensive operations
  89. * (for example, <code>String</code> concatenation)
  90. * when the log level is more than info. </p>
  91. */
  92. public boolean isInfoEnabled();
  93. /**
  94. * <p> Is trace logging currently enabled? </p>
  95. *
  96. * <p> Call this method to prevent having to perform expensive operations
  97. * (for example, <code>String</code> concatenation)
  98. * when the log level is more than trace. </p>
  99. */
  100. public boolean isTraceEnabled();
  101. /**
  102. * <p> Is warn logging currently enabled? </p>
  103. *
  104. * <p> Call this method to prevent having to perform expensive operations
  105. * (for example, <code>String</code> concatenation)
  106. * when the log level is more than warn. </p>
  107. */
  108. public boolean isWarnEnabled();
  109. // -------------------------------------------------------- Logging Methods
  110. /**
  111. * <p> Log a message with trace log level. </p>
  112. *
  113. * @param message log this message
  114. */
  115. public void trace(Object message);
  116. /**
  117. * <p> Log an error with trace log level. </p>
  118. *
  119. * @param message log this message
  120. * @param t log this cause
  121. */
  122. public void trace(Object message, Throwable t);
  123. /**
  124. * <p> Log a message with debug log level. </p>
  125. *
  126. * @param message log this message
  127. */
  128. public void debug(Object message);
  129. /**
  130. * <p> Log an error with debug log level. </p>
  131. *
  132. * @param message log this message
  133. * @param t log this cause
  134. */
  135. public void debug(Object message, Throwable t);
  136. /**
  137. * <p> Log a message with info log level. </p>
  138. *
  139. * @param message log this message
  140. */
  141. public void info(Object message);
  142. /**
  143. * <p> Log an error with info log level. </p>
  144. *
  145. * @param message log this message
  146. * @param t log this cause
  147. */
  148. public void info(Object message, Throwable t);
  149. /**
  150. * <p> Log a message with warn log level. </p>
  151. *
  152. * @param message log this message
  153. */
  154. public void warn(Object message);
  155. /**
  156. * <p> Log an error with warn log level. </p>
  157. *
  158. * @param message log this message
  159. * @param t log this cause
  160. */
  161. public void warn(Object message, Throwable t);
  162. /**
  163. * <p> Log a message with error log level. </p>
  164. *
  165. * @param message log this message
  166. */
  167. public void error(Object message);
  168. /**
  169. * <p> Log an error with error log level. </p>
  170. *
  171. * @param message log this message
  172. * @param t log this cause
  173. */
  174. public void error(Object message, Throwable t);
  175. /**
  176. * <p> Log a message with fatal log level. </p>
  177. *
  178. * @param message log this message
  179. */
  180. public void fatal(Object message);
  181. /**
  182. * <p> Log an error with fatal log level. </p>
  183. *
  184. * @param message log this message
  185. * @param t log this cause
  186. */
  187. public void fatal(Object message, Throwable t);
  188. }