1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 19 package org.apache.commons.logging; 20 21 /** 22 * <p>A simple logging interface abstracting logging APIs. In order to be 23 * instantiated successfully by {@link LogFactory}, classes that implement 24 * this interface must have a constructor that takes a single String 25 * parameter representing the "name" of this Log.</p> 26 * 27 * <p> The six logging levels used by <code>Log</code> are (in order): 28 * <ol> 29 * <li>trace (the least serious)</li> 30 * <li>debug</li> 31 * <li>info</li> 32 * <li>warn</li> 33 * <li>error</li> 34 * <li>fatal (the most serious)</li> 35 * </ol> 36 * The mapping of these log levels to the concepts used by the underlying 37 * logging system is implementation dependent. 38 * The implemention should ensure, though, that this ordering behaves 39 * as expected.</p> 40 * 41 * <p>Performance is often a logging concern. 42 * By examining the appropriate property, 43 * a component can avoid expensive operations (producing information 44 * to be logged).</p> 45 * 46 * <p> For example, 47 * <code><pre> 48 * if (log.isDebugEnabled()) { 49 * ... do something expensive ... 50 * log.debug(theResult); 51 * } 52 * </pre></code> 53 * </p> 54 * 55 * <p>Configuration of the underlying logging system will generally be done 56 * external to the Logging APIs, through whatever mechanism is supported by 57 * that system.</p> 58 * 59 * @author <a href="mailto:sanders@apache.org">Scott Sanders</a> 60 * @author Rod Waldhoff 61 * @version $Id: Log.java 424107 2006-07-20 23:15:42Z skitching $ 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 * @return true if debug is enabled in the underlying logger. 77 */ 78 public boolean isDebugEnabled(); 79 80 81 /** 82 * <p> Is error logging currently enabled? </p> 83 * 84 * <p> Call this method to prevent having to perform expensive operations 85 * (for example, <code>String</code> concatenation) 86 * when the log level is more than error. </p> 87 * 88 * @return true if error is enabled in the underlying logger. 89 */ 90 public boolean isErrorEnabled(); 91 92 93 /** 94 * <p> Is fatal logging currently enabled? </p> 95 * 96 * <p> Call this method to prevent having to perform expensive operations 97 * (for example, <code>String</code> concatenation) 98 * when the log level is more than fatal. </p> 99 * 100 * @return true if fatal is enabled in the underlying logger. 101 */ 102 public boolean isFatalEnabled(); 103 104 105 /** 106 * <p> Is info logging currently enabled? </p> 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 info. </p> 111 * 112 * @return true if info is enabled in the underlying logger. 113 */ 114 public boolean isInfoEnabled(); 115 116 117 /** 118 * <p> Is trace logging currently enabled? </p> 119 * 120 * <p> Call this method to prevent having to perform expensive operations 121 * (for example, <code>String</code> concatenation) 122 * when the log level is more than trace. </p> 123 * 124 * @return true if trace is enabled in the underlying logger. 125 */ 126 public boolean isTraceEnabled(); 127 128 129 /** 130 * <p> Is warn logging currently enabled? </p> 131 * 132 * <p> Call this method to prevent having to perform expensive operations 133 * (for example, <code>String</code> concatenation) 134 * when the log level is more than warn. </p> 135 * 136 * @return true if warn is enabled in the underlying logger. 137 */ 138 public boolean isWarnEnabled(); 139 140 141 // -------------------------------------------------------- Logging Methods 142 143 144 /** 145 * <p> Log a message with trace log level. </p> 146 * 147 * @param message log this message 148 */ 149 public void trace(Object message); 150 151 152 /** 153 * <p> Log an error with trace log level. </p> 154 * 155 * @param message log this message 156 * @param t log this cause 157 */ 158 public void trace(Object message, Throwable t); 159 160 161 /** 162 * <p> Log a message with debug log level. </p> 163 * 164 * @param message log this message 165 */ 166 public void debug(Object message); 167 168 169 /** 170 * <p> Log an error with debug log level. </p> 171 * 172 * @param message log this message 173 * @param t log this cause 174 */ 175 public void debug(Object message, Throwable t); 176 177 178 /** 179 * <p> Log a message with info log level. </p> 180 * 181 * @param message log this message 182 */ 183 public void info(Object message); 184 185 186 /** 187 * <p> Log an error with info log level. </p> 188 * 189 * @param message log this message 190 * @param t log this cause 191 */ 192 public void info(Object message, Throwable t); 193 194 195 /** 196 * <p> Log a message with warn log level. </p> 197 * 198 * @param message log this message 199 */ 200 public void warn(Object message); 201 202 203 /** 204 * <p> Log an error with warn log level. </p> 205 * 206 * @param message log this message 207 * @param t log this cause 208 */ 209 public void warn(Object message, Throwable t); 210 211 212 /** 213 * <p> Log a message with error log level. </p> 214 * 215 * @param message log this message 216 */ 217 public void error(Object message); 218 219 220 /** 221 * <p> Log an error with error log level. </p> 222 * 223 * @param message log this message 224 * @param t log this cause 225 */ 226 public void error(Object message, Throwable t); 227 228 229 /** 230 * <p> Log a message with fatal log level. </p> 231 * 232 * @param message log this message 233 */ 234 public void fatal(Object message); 235 236 237 /** 238 * <p> Log an error with fatal log level. </p> 239 * 240 * @param message log this message 241 * @param t log this cause 242 */ 243 public void fatal(Object message, Throwable t); 244 245 246 }