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.</p>
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.</p>
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).</p>
43   *
44   * <p> For example,
45   * <code><pre>
46   *    if (log.isDebugEnabled()) {
47   *        ... do something expensive ...
48   *        log.debug(theResult);
49   *    }
50   * </pre></code>
51   * </p>
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.</p>
56   *
57   * <p style="color: #E40; font-weight: bold;">Please note that this interface is identical to that found in JCL 1.1.1.</p>
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  
66      // ----------------------------------------------------- Logging Properties
67  
68  
69      /**
70       * <p> Is debug 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 debug. </p>
75       */
76      public boolean isDebugEnabled();
77  
78  
79      /**
80       * <p> Is error logging currently enabled? </p>
81       *
82       * <p> Call this method to prevent having to perform expensive operations
83       * (for example, <code>String</code> concatenation)
84       * when the log level is more than error. </p>
85       */
86      public boolean isErrorEnabled();
87  
88  
89      /**
90       * <p> Is fatal logging currently enabled? </p>
91       *
92       * <p> Call this method to prevent having to perform expensive operations
93       * (for example, <code>String</code> concatenation)
94       * when the log level is more than fatal. </p>
95       */
96      public boolean isFatalEnabled();
97  
98  
99      /**
100      * <p> Is info logging currently enabled? </p>
101      *
102      * <p> Call this method to prevent having to perform expensive operations
103      * (for example, <code>String</code> concatenation)
104      * when the log level is more than info. </p>
105      * 
106      * @return true if info enabled, false otherwise
107      */
108     public boolean isInfoEnabled();
109 
110 
111     /**
112      * <p> Is trace logging currently enabled? </p>
113      *
114      * <p> Call this method to prevent having to perform expensive operations
115      * (for example, <code>String</code> concatenation)
116      * when the log level is more than trace. </p>
117      * 
118      * @return true if trace enabled, false otherwise
119      */
120     public boolean isTraceEnabled();
121 
122 
123     /**
124      * <p> Is warn logging currently enabled? </p>
125      *
126      * <p> Call this method to prevent having to perform expensive operations
127      * (for example, <code>String</code> concatenation)
128      * when the log level is more than warn. </p>
129      */
130     public boolean isWarnEnabled();
131 
132 
133     // -------------------------------------------------------- Logging Methods
134 
135 
136     /**
137      * <p> Log a message with trace log level. </p>
138      *
139      * @param message log this message
140      */
141     public void trace(Object message);
142 
143 
144     /**
145      * <p> Log an error with trace log level. </p>
146      *
147      * @param message log this message
148      * @param t log this cause
149      */
150     public void trace(Object message, Throwable t);
151 
152 
153     /**
154      * <p> Log a message with debug log level. </p>
155      *
156      * @param message log this message
157      */
158     public void debug(Object message);
159 
160 
161     /**
162      * <p> Log an error with debug log level. </p>
163      *
164      * @param message log this message
165      * @param t log this cause
166      */
167     public void debug(Object message, Throwable t);
168 
169 
170     /**
171      * <p> Log a message with info log level. </p>
172      *
173      * @param message log this message
174      */
175     public void info(Object message);
176 
177 
178     /**
179      * <p> Log an error with info log level. </p>
180      *
181      * @param message log this message
182      * @param t log this cause
183      */
184     public void info(Object message, Throwable t);
185 
186 
187     /**
188      * <p> Log a message with warn log level. </p>
189      *
190      * @param message log this message
191      */
192     public void warn(Object message);
193 
194 
195     /**
196      * <p> Log an error with warn log level. </p>
197      *
198      * @param message log this message
199      * @param t log this cause
200      */
201     public void warn(Object message, Throwable t);
202 
203 
204     /**
205      * <p> Log a message with error log level. </p>
206      *
207      * @param message log this message
208      */
209     public void error(Object message);
210 
211 
212     /**
213      * <p> Log an error with error log level. </p>
214      *
215      * @param message log this message
216      * @param t log this cause
217      */
218     public void error(Object message, Throwable t);
219 
220 
221     /**
222      * <p> Log a message with fatal log level. </p>
223      *
224      * @param message log this message
225      */
226     public void fatal(Object message);
227 
228 
229     /**
230      * <p> Log an error with fatal log level. </p>
231      *
232      * @param message log this message
233      * @param t log this cause
234      */
235     public void fatal(Object message, Throwable t);
236 
237 
238 }