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 public boolean isInfoEnabled(); 107 108 109 /** 110 * <p> Is trace logging currently enabled? </p> 111 * 112 * <p> Call this method to prevent having to perform expensive operations 113 * (for example, <code>String</code> concatenation) 114 * when the log level is more than trace. </p> 115 */ 116 public boolean isTraceEnabled(); 117 118 119 /** 120 * <p> Is warn logging currently enabled? </p> 121 * 122 * <p> Call this method to prevent having to perform expensive operations 123 * (for example, <code>String</code> concatenation) 124 * when the log level is more than warn. </p> 125 */ 126 public boolean isWarnEnabled(); 127 128 129 // -------------------------------------------------------- Logging Methods 130 131 132 /** 133 * <p> Log a message with trace log level. </p> 134 * 135 * @param message log this message 136 */ 137 public void trace(Object message); 138 139 140 /** 141 * <p> Log an error with trace log level. </p> 142 * 143 * @param message log this message 144 * @param t log this cause 145 */ 146 public void trace(Object message, Throwable t); 147 148 149 /** 150 * <p> Log a message with debug log level. </p> 151 * 152 * @param message log this message 153 */ 154 public void debug(Object message); 155 156 157 /** 158 * <p> Log an error with debug log level. </p> 159 * 160 * @param message log this message 161 * @param t log this cause 162 */ 163 public void debug(Object message, Throwable t); 164 165 166 /** 167 * <p> Log a message with info log level. </p> 168 * 169 * @param message log this message 170 */ 171 public void info(Object message); 172 173 174 /** 175 * <p> Log an error with info log level. </p> 176 * 177 * @param message log this message 178 * @param t log this cause 179 */ 180 public void info(Object message, Throwable t); 181 182 183 /** 184 * <p> Log a message with warn log level. </p> 185 * 186 * @param message log this message 187 */ 188 public void warn(Object message); 189 190 191 /** 192 * <p> Log an error with warn log level. </p> 193 * 194 * @param message log this message 195 * @param t log this cause 196 */ 197 public void warn(Object message, Throwable t); 198 199 200 /** 201 * <p> Log a message with error log level. </p> 202 * 203 * @param message log this message 204 */ 205 public void error(Object message); 206 207 208 /** 209 * <p> Log an error with error log level. </p> 210 * 211 * @param message log this message 212 * @param t log this cause 213 */ 214 public void error(Object message, Throwable t); 215 216 217 /** 218 * <p> Log a message with fatal log level. </p> 219 * 220 * @param message log this message 221 */ 222 public void fatal(Object message); 223 224 225 /** 226 * <p> Log an error with fatal log level. </p> 227 * 228 * @param message log this message 229 * @param t log this cause 230 */ 231 public void fatal(Object message, Throwable t); 232 233 234 }