001/*
002 * Copyright 2001-2004 The Apache Software Foundation.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.apache.commons.logging;
018
019/**
020 * <p>A simple logging interface abstracting logging APIs.  In order to be
021 * instantiated successfully by {@link LogFactory}, classes that implement
022 * this interface must have a constructor that takes a single String
023 * parameter representing the "name" of this Log.
024 *
025 * <p> The six logging levels used by <code>Log</code> are (in order):
026 * <ol>
027 * <li>trace (the least serious)</li>
028 * <li>debug</li>
029 * <li>info</li>
030 * <li>warn</li>
031 * <li>error</li>
032 * <li>fatal (the most serious)</li>
033 * </ol>
034 * The mapping of these log levels to the concepts used by the underlying
035 * logging system is implementation dependent.
036 * The implementation should ensure, though, that this ordering behaves
037 * as expected.
038 *
039 * <p>Performance is often a logging concern.
040 * By examining the appropriate property,
041 * a component can avoid expensive operations (producing information
042 * to be logged).
043 *
044 * <p> For example,
045 * <pre>
046 *    if (log.isDebugEnabled()) {
047 *        ... do something expensive ...
048 *        log.debug(theResult);
049 *    }
050 * </pre>
051 * 
052 *
053 * <p>Configuration of the underlying logging system will generally be done
054 * external to the Logging APIs, through whatever mechanism is supported by
055 * that system.
056 *
057 * <p style="color: #E40; font-weight: bold;">Please note that this interface is identical to that found in JCL 1.1.1.
058 * 
059 * @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
060 * @author Rod Waldhoff
061 * @version $Id: Log.java,v 1.19 2004/06/06 21:16:04 rdonkin Exp $
062 */
063public interface Log {
064
065    // ----------------------------------------------------- Logging Properties
066
067    /**
068     * <p> Is debug logging currently enabled? 
069     *
070     * <p> Call this method to prevent having to perform expensive operations
071     * (for example, <code>String</code> concatenation)
072     * when the log level is more than debug. 
073     */
074    public boolean isDebugEnabled();
075
076    /**
077     * <p> Is error logging currently enabled? 
078     *
079     * <p> Call this method to prevent having to perform expensive operations
080     * (for example, <code>String</code> concatenation)
081     * when the log level is more than error. 
082     */
083    public boolean isErrorEnabled();
084
085    /**
086     * <p> Is fatal logging currently enabled? 
087     *
088     * <p> Call this method to prevent having to perform expensive operations
089     * (for example, <code>String</code> concatenation)
090     * when the log level is more than fatal. 
091     */
092    public boolean isFatalEnabled();
093
094    /**
095     * <p> Is info logging currently enabled? 
096     *
097     * <p> Call this method to prevent having to perform expensive operations
098     * (for example, <code>String</code> concatenation)
099     * 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}