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