1packageorg.apache.jetspeed.services.logging;
2/*3 * Copyright 2001,2004 The Apache Software Foundation.4 * 5 * Licensed under the Apache License, Version 2.0 (the "License");6 * you may not use this file except in compliance with the License.7 * You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * 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 and15 * limitations under the License.16 */1718// Log4J classes19import org.apache.log4j.Level;
20import org.apache.log4j.LogManager;
21import org.apache.log4j.Logger;
2223/***24 * The implementation of loggers for Jetspeed.25 *26 * This class acts as a wrapper so that the underlying logging implementation27 * is hidden fromthe rest of Jetspeed28 * The current implementation uses Log4J.29 *30 * @author <a href="mailto:harald@ommang.com">Harald Ommang</a>31 */32publicclassJetspeedLogger33 {
3435/***36 * The Log4J logger that is wrapped37 */38private Logger logger;
3940/***41 * Constructor. Initialises this class with a given logger.42 * If the logger is null, one is given named from this class.43 *44 * @param logger The logger to wrap45 */46publicJetspeedLogger(Logger logger)
47 {
48if(logger != null)
49 {
50this.logger = logger;
51 } else52 {
53this.logger = LogManager.getLogger(JetspeedLogger.class.getName());
54 }
55 }
5657/***58 * Checks if the current logger is enabled for debug logging.59 *60 * @return true if debug is enabled61 */62publicboolean isDebugEnabled()
63 {
64return logger.isDebugEnabled();
65 }
6667/***68 * Checks if the current logger is enabled for error logging.69 *70 * @return true if error is enabled71 */72publicboolean isErrorEnabled()
73 {
74return logger.isEnabledFor(Level.ERROR);
75 }
7677/***78 * Checks if the current logger is enabled for fatal logging.79 *80 * @return true if fatal is enabled81 */82publicboolean isFatalEnabled()
83 {
84return logger.isEnabledFor(Level.FATAL);
85 }
8687/***88 * Checks if the current logger is enabled for info logging.89 *90 * @return true if info is enabled91 */92publicboolean isInfoEnabled()
93 {
94return logger.isInfoEnabled();
95 }
9697/***98 * Checks if the current logger is enabled for trace logging.99 * Wtih log4J, this is the same as debug.100 *101 * @return true if trace is enabled102 */103publicboolean isTraceEnabled()
104 {
105return logger.isDebugEnabled();
106 }
107108/***109 * Checks if the current logger is enabled for warning logging.110 *111 * @return true if warning is enabled112 */113publicboolean isWarnEnabled()
114 {
115return logger.isEnabledFor(Level.WARN);
116 }
117118/***119 * Logs the given object if debug is enabled120 *121 * @param obj Object to log122 */123publicvoid debug(Object obj)
124 {
125 logger.debug(obj);
126 }
127128/***129 * Logs the given object and throwable if debug is enabled130 *131 * @param obj Object to log132 * @param throwable The underlying implementation may log stack trace for this133 */134publicvoid debug(Object obj, Throwable throwable)
135 {
136 logger.debug(obj, throwable);
137 }
138139/***140 * Logs the given object if error is enabled141 *142 * @param obj Object to log143 */144publicvoid error(Object obj)
145 {
146 logger.error(obj);
147 }
148149/***150 * Logs the given object and throwable if error is enabled151 *152 * @param obj Object to log153 * @param throwable The underlying implementation may log stack trace for this154 */155publicvoid error(Object obj, Throwable throwable)
156 {
157 logger.error(obj, throwable);
158 }
159160/***161 * Logs the given object if fatal is enabled162 *163 * @param obj Object to log164 */165publicvoid fatal(Object obj)
166 {
167 logger.fatal(obj);
168 }
169170/***171 * Logs the given object and throwable if fatal is enabled172 *173 * @param obj Object to log174 * @param throwable The underlying implementation may log stack trace for this175 */176publicvoid fatal(Object obj, Throwable throwable)
177 {
178 logger.fatal(obj, throwable);
179 }
180181/***182 * Logs the given object if info is enabled183 *184 * @param obj Object to log185 */186publicvoid info(Object obj)
187 {
188 logger.info(obj);
189 }
190191/***192 * Logs the given object and throwable if info is enabled193 *194 * @param obj Object to log195 * @param throwable The underlying implementation may log stack trace for this196 */197publicvoid info(Object obj, Throwable throwable)
198 {
199 logger.info(obj, throwable);
200 }
201202/***203 * Logs the given object if trace is enabled204 * With Log4J, this is the same as debug205 *206 * @param obj Object to log207 */208publicvoid trace(Object obj)
209 {
210 logger.debug(obj);
211 }
212213/***214 * Logs the given object and throwable if trace is enabled215 * With Log4J, this is the same as debug216 *217 * @param obj Object to log218 * @param throwable The underlying implementation may log stack trace for this219 */220publicvoid trace(Object obj, Throwable throwable)
221 {
222 logger.debug(obj, throwable);
223 }
224225/***226 * Logs the given object if warning is enabled227 *228 * @param obj Object to log229 */230publicvoid warn(Object obj)
231 {
232 logger.warn(obj);
233 }
234235/***236 * Logs the given object and throwable if warning is enabled237 *238 * @param obj Object to log239 * @param throwable The underlying implementation may log stack trace for this240 */241publicvoid warn(Object obj, Throwable throwable)
242 {
243 logger.warn(obj, throwable);
244 }
245 } // class JetspeedLogger246