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.impl;
  17. import org.apache.commons.logging.Log;
  18. import org.apache.log4j.Category;
  19. import org.apache.log4j.Priority;
  20. /**
  21. * <p>Implementation of {@link Log} that maps directly to a Log4J
  22. * <strong>Category</strong>. Initial configuration of the corresponding
  23. * Category instances should be done in the usual manner, as outlined in
  24. * the Log4J documentation.</p>
  25. *
  26. * @deprecated Use {@link Log4JLogger} instead.
  27. *
  28. * @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
  29. * @author Rod Waldhoff
  30. * @author Robert Burrell Donkin
  31. * @version $Id: Log4JCategoryLog.java,v 1.15 2004/02/28 21:46:45 craigmcc Exp $
  32. */
  33. public final class Log4JCategoryLog implements Log {
  34. // ------------------------------------------------------------- Attributes
  35. /** The fully qualified name of the Log4JCategoryLog class. */
  36. private static final String FQCN = Log4JCategoryLog.class.getName();
  37. /** Log to this category */
  38. private Category category = null;
  39. // ------------------------------------------------------------ Constructor
  40. public Log4JCategoryLog() {
  41. }
  42. /**
  43. * Base constructor.
  44. */
  45. public Log4JCategoryLog(String name) {
  46. this.category=Category.getInstance(name);
  47. }
  48. /** For use with a log4j factory.
  49. */
  50. public Log4JCategoryLog(Category category ) {
  51. this.category=category;
  52. }
  53. // ---------------------------------------------------------- Implmentation
  54. /**
  55. * Log a message to the Log4j Category with <code>TRACE</code> priority.
  56. * Currently logs to <code>DEBUG</code> level in Log4J.
  57. */
  58. public void trace(Object message) {
  59. category.log(FQCN, Priority.DEBUG, message, null);
  60. }
  61. /**
  62. * Log an error to the Log4j Category with <code>TRACE</code> priority.
  63. * Currently logs to <code>DEBUG</code> level in Log4J.
  64. */
  65. public void trace(Object message, Throwable t) {
  66. category.log(FQCN, Priority.DEBUG, message, t );
  67. }
  68. /**
  69. * Log a message to the Log4j Category with <code>DEBUG</code> priority.
  70. */
  71. public void debug(Object message) {
  72. category.log(FQCN, Priority.DEBUG, message, null);
  73. }
  74. /**
  75. * Log an error to the Log4j Category with <code>DEBUG</code> priority.
  76. */
  77. public void debug(Object message, Throwable t) {
  78. category.log(FQCN, Priority.DEBUG, message, t );
  79. }
  80. /**
  81. * Log a message to the Log4j Category with <code>INFO</code> priority.
  82. */
  83. public void info(Object message) {
  84. category.log(FQCN, Priority.INFO, message, null );
  85. }
  86. /**
  87. * Log an error to the Log4j Category with <code>INFO</code> priority.
  88. */
  89. public void info(Object message, Throwable t) {
  90. category.log(FQCN, Priority.INFO, message, t );
  91. }
  92. /**
  93. * Log a message to the Log4j Category with <code>WARN</code> priority.
  94. */
  95. public void warn(Object message) {
  96. category.log(FQCN, Priority.WARN, message, null );
  97. }
  98. /**
  99. * Log an error to the Log4j Category with <code>WARN</code> priority.
  100. */
  101. public void warn(Object message, Throwable t) {
  102. category.log(FQCN, Priority.WARN, message, t );
  103. }
  104. /**
  105. * Log a message to the Log4j Category with <code>ERROR</code> priority.
  106. */
  107. public void error(Object message) {
  108. category.log(FQCN, Priority.ERROR, message, null );
  109. }
  110. /**
  111. * Log an error to the Log4j Category with <code>ERROR</code> priority.
  112. */
  113. public void error(Object message, Throwable t) {
  114. category.log(FQCN, Priority.ERROR, message, t );
  115. }
  116. /**
  117. * Log a message to the Log4j Category with <code>FATAL</code> priority.
  118. */
  119. public void fatal(Object message) {
  120. category.log(FQCN, Priority.FATAL, message, null );
  121. }
  122. /**
  123. * Log an error to the Log4j Category with <code>FATAL</code> priority.
  124. */
  125. public void fatal(Object message, Throwable t) {
  126. category.log(FQCN, Priority.FATAL, message, t );
  127. }
  128. /**
  129. * Return the native Category instance we are using.
  130. */
  131. public Category getCategory() {
  132. return (this.category);
  133. }
  134. /**
  135. * Check whether the Log4j Category used is enabled for <code>DEBUG</code> priority.
  136. */
  137. public boolean isDebugEnabled() {
  138. return category.isDebugEnabled();
  139. }
  140. /**
  141. * Check whether the Log4j Category used is enabled for <code>ERROR</code> priority.
  142. */
  143. public boolean isErrorEnabled() {
  144. return category.isEnabledFor(Priority.ERROR);
  145. }
  146. /**
  147. * Check whether the Log4j Category used is enabled for <code>FATAL</code> priority.
  148. */
  149. public boolean isFatalEnabled() {
  150. return category.isEnabledFor(Priority.FATAL);
  151. }
  152. /**
  153. * Check whether the Log4j Category used is enabled for <code>INFO</code> priority.
  154. */
  155. public boolean isInfoEnabled() {
  156. return category.isInfoEnabled();
  157. }
  158. /**
  159. * Check whether the Log4j Category used is enabled for <code>TRACE</code> priority.
  160. * For Log4J, this returns the value of <code>isDebugEnabled()</code>
  161. */
  162. public boolean isTraceEnabled() {
  163. return category.isDebugEnabled();
  164. }
  165. /**
  166. * Check whether the Log4j Category used is enabled for <code>WARN</code> priority.
  167. */
  168. public boolean isWarnEnabled() {
  169. return category.isEnabledFor(Priority.WARN);
  170. }
  171. }