001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * https://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.commons.logging; 019 020/** 021 * A simple logging interface abstracting logging APIs. In order to be 022 * instantiated successfully by {@link LogFactory}, classes that implement 023 * this interface must have a constructor that takes a single String 024 * parameter representing the "name" of this Log. 025 * 026 * <p>The six logging levels used by <code>Log</code> are (in order): 027 * <ol> 028 * <li>trace (the least serious)</li> 029 * <li>debug</li> 030 * <li>info</li> 031 * <li>warn</li> 032 * <li>error</li> 033 * <li>fatal (the most serious)</li> 034 * </ol> 035 * 036 * The mapping of these log levels to the concepts used by the underlying 037 * logging system is implementation dependent. 038 * The implementation should ensure, though, that this ordering behaves 039 * as expected. 040 * 041 * <p>Performance is often a logging concern. 042 * By examining the appropriate property, 043 * a component can avoid expensive operations (producing information 044 * to be logged). 045 * 046 * <p>For example, 047 * <pre> 048 * if (log.isDebugEnabled()) { 049 * ... do something expensive ... 050 * log.debug(theResult); 051 * } 052 * </pre> 053 * 054 * <p>Configuration of the underlying logging system will generally be done 055 * external to the Logging APIs, through whatever mechanism is supported by 056 * that system. 057 * 058 * @author Juergen Hoeller (for the {@code spring-jcl} variant) 059 * @since 5.0 060 */ 061public interface Log { 062 063 /** 064 * Is fatal logging currently enabled? 065 * <p>Call this method to prevent having to perform expensive operations 066 * (for example, <code>String</code> concatenation) 067 * when the log level is more than fatal. 068 * @return true if fatal is enabled in the underlying logger. 069 */ 070 boolean isFatalEnabled(); 071 072 /** 073 * Is error logging currently enabled? 074 * <p>Call this method to prevent having to perform expensive operations 075 * (for example, <code>String</code> concatenation) 076 * when the log level is more than error. 077 * @return true if error is enabled in the underlying logger. 078 */ 079 boolean isErrorEnabled(); 080 081 /** 082 * Is warn logging currently enabled? 083 * <p>Call this method to prevent having to perform expensive operations 084 * (for example, <code>String</code> concatenation) 085 * when the log level is more than warn. 086 * @return true if warn is enabled in the underlying logger. 087 */ 088 boolean isWarnEnabled(); 089 090 /** 091 * Is info logging currently enabled? 092 * <p>Call this method to prevent having to perform expensive operations 093 * (for example, <code>String</code> concatenation) 094 * when the log level is more than info. 095 * @return true if info is enabled in the underlying logger. 096 */ 097 boolean isInfoEnabled(); 098 099 /** 100 * Is debug logging currently enabled? 101 * <p>Call this method to prevent having to perform expensive operations 102 * (for example, <code>String</code> concatenation) 103 * when the log level is more than debug. 104 * @return true if debug is enabled in the underlying logger. 105 */ 106 boolean isDebugEnabled(); 107 108 /** 109 * Is trace logging currently enabled? 110 * <p>Call this method to prevent having to perform expensive operations 111 * (for example, <code>String</code> concatenation) 112 * when the log level is more than trace. 113 * @return true if trace is enabled in the underlying logger. 114 */ 115 boolean isTraceEnabled(); 116 117 118 /** 119 * Logs a message with fatal log level. 120 * @param message log this message 121 */ 122 void fatal(Object message); 123 124 /** 125 * Logs an error with fatal log level. 126 * @param message log this message 127 * @param t log this cause 128 */ 129 void fatal(Object message, Throwable t); 130 131 /** 132 * Logs a message with error log level. 133 * @param message log this message 134 */ 135 void error(Object message); 136 137 /** 138 * Logs an error with error log level. 139 * @param message log this message 140 * @param t log this cause 141 */ 142 void error(Object message, Throwable t); 143 144 /** 145 * Logs a message with warn log level. 146 * @param message log this message 147 */ 148 void warn(Object message); 149 150 /** 151 * Logs an error with warn log level. 152 * @param message log this message 153 * @param t log this cause 154 */ 155 void warn(Object message, Throwable t); 156 157 /** 158 * Logs a message with info log level. 159 * @param message log this message 160 */ 161 void info(Object message); 162 163 /** 164 * Logs an error with info log level. 165 * @param message log this message 166 * @param t log this cause 167 */ 168 void info(Object message, Throwable t); 169 170 /** 171 * Logs a message with debug log level. 172 * @param message log this message 173 */ 174 void debug(Object message); 175 176 /** 177 * Logs an error with debug log level. 178 * @param message log this message 179 * @param t log this cause 180 */ 181 void debug(Object message, Throwable t); 182 183 /** 184 * Logs a message with trace log level. 185 * @param message log this message 186 */ 187 void trace(Object message); 188 189 /** 190 * Logs an error with trace log level. 191 * @param message log this message 192 * @param t log this cause 193 */ 194 void trace(Object message, Throwable t); 195 196}