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 package org.apache.commons.logging.impl; 19 20 import java.io.Serializable; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.log.Hierarchy; 24 import org.apache.log.Logger; 25 26 /** 27 * Implements {@code org.apache.commons.logging.Log} 28 * to wrap the <a href="https://avalon.apache.org/logkit/">Apache Avalon Logkit</a> 29 * logging system. Configuration of {@code LogKit} is left to the user. 30 * <p> 31 * {@code LogKit} accepts only {@code String} messages. 32 * Therefore, this implementation converts object messages into strings 33 * by called their {@code toString()} method before logging them. 34 * </p> 35 * 36 * @deprecated Scheduled for removal because the Apache Avalon Project has been discontinued. 37 */ 38 @Deprecated 39 public class LogKitLogger implements Log, Serializable { 40 41 /** Serializable version identifier. */ 42 private static final long serialVersionUID = 3768538055836059519L; 43 44 /** Logging goes to this {@code LogKit} logger */ 45 protected transient volatile Logger logger; 46 47 /** Name of this logger */ 48 protected String name; 49 50 /** 51 * Constructs {@code LogKitLogger} which wraps the {@code LogKit} 52 * logger with given name. 53 * 54 * @param name log name 55 */ 56 public LogKitLogger(final String name) { 57 this.name = name; 58 this.logger = getLogger(); 59 } 60 61 /** 62 * Logs a message with {@code org.apache.log.Priority.DEBUG}. 63 * 64 * @param message to log 65 * @see org.apache.commons.logging.Log#debug(Object) 66 */ 67 @Override 68 public void debug(final Object message) { 69 if (message != null) { 70 getLogger().debug(String.valueOf(message)); 71 } 72 } 73 74 /** 75 * Logs a message with {@code org.apache.log.Priority.DEBUG}. 76 * 77 * @param message to log 78 * @param t log this cause 79 * @see org.apache.commons.logging.Log#debug(Object, Throwable) 80 */ 81 @Override 82 public void debug(final Object message, final Throwable t) { 83 if (message != null) { 84 getLogger().debug(String.valueOf(message), t); 85 } 86 } 87 88 /** 89 * Logs a message with {@code org.apache.log.Priority.ERROR}. 90 * 91 * @param message to log 92 * @see org.apache.commons.logging.Log#error(Object) 93 */ 94 @Override 95 public void error(final Object message) { 96 if (message != null) { 97 getLogger().error(String.valueOf(message)); 98 } 99 } 100 101 /** 102 * Logs a message with {@code org.apache.log.Priority.ERROR}. 103 * 104 * @param message to log 105 * @param t log this cause 106 * @see org.apache.commons.logging.Log#error(Object, Throwable) 107 */ 108 @Override 109 public void error(final Object message, final Throwable t) { 110 if (message != null) { 111 getLogger().error(String.valueOf(message), t); 112 } 113 } 114 115 /** 116 * Logs a message with {@code org.apache.log.Priority.FATAL_ERROR}. 117 * 118 * @param message to log 119 * @see org.apache.commons.logging.Log#fatal(Object) 120 */ 121 @Override 122 public void fatal(final Object message) { 123 if (message != null) { 124 getLogger().fatalError(String.valueOf(message)); 125 } 126 } 127 128 /** 129 * Logs a message with {@code org.apache.log.Priority.FATAL_ERROR}. 130 * 131 * @param message to log 132 * @param t log this cause 133 * @see org.apache.commons.logging.Log#fatal(Object, Throwable) 134 */ 135 @Override 136 public void fatal(final Object message, final Throwable t) { 137 if (message != null) { 138 getLogger().fatalError(String.valueOf(message), t); 139 } 140 } 141 142 /** 143 * Gets the underlying Logger we are using. 144 * 145 * @return the underlying Logger we are using. 146 */ 147 public Logger getLogger() { 148 Logger result = logger; 149 if (result == null) { 150 synchronized(this) { 151 result = logger; 152 if (result == null) { 153 logger = result = Hierarchy.getDefaultHierarchy().getLoggerFor(name); 154 } 155 } 156 } 157 return result; 158 } 159 160 /** 161 * Logs a message with {@code org.apache.log.Priority.INFO}. 162 * 163 * @param message to log 164 * @see org.apache.commons.logging.Log#info(Object) 165 */ 166 @Override 167 public void info(final Object message) { 168 if (message != null) { 169 getLogger().info(String.valueOf(message)); 170 } 171 } 172 173 /** 174 * Logs a message with {@code org.apache.log.Priority.INFO}. 175 * 176 * @param message to log 177 * @param t log this cause 178 * @see org.apache.commons.logging.Log#info(Object, Throwable) 179 */ 180 @Override 181 public void info(final Object message, final Throwable t) { 182 if (message != null) { 183 getLogger().info(String.valueOf(message), t); 184 } 185 } 186 187 /** 188 * Checks whether the {@code LogKit} logger will log messages of priority {@code DEBUG}. 189 */ 190 @Override 191 public boolean isDebugEnabled() { 192 return getLogger().isDebugEnabled(); 193 } 194 195 /** 196 * Checks whether the {@code LogKit} logger will log messages of priority {@code ERROR}. 197 */ 198 @Override 199 public boolean isErrorEnabled() { 200 return getLogger().isErrorEnabled(); 201 } 202 203 /** 204 * Checks whether the {@code LogKit} logger will log messages of priority {@code FATAL_ERROR}. 205 */ 206 @Override 207 public boolean isFatalEnabled() { 208 return getLogger().isFatalErrorEnabled(); 209 } 210 211 /** 212 * Checks whether the {@code LogKit} logger will log messages of priority {@code INFO}. 213 */ 214 @Override 215 public boolean isInfoEnabled() { 216 return getLogger().isInfoEnabled(); 217 } 218 219 /** 220 * Checks whether the {@code LogKit} logger will log messages of priority {@code DEBUG}. 221 */ 222 @Override 223 public boolean isTraceEnabled() { 224 return getLogger().isDebugEnabled(); 225 } 226 227 /** 228 * Checks whether the {@code LogKit} logger will log messages of priority {@code WARN}. 229 */ 230 @Override 231 public boolean isWarnEnabled() { 232 return getLogger().isWarnEnabled(); 233 } 234 235 /** 236 * Logs a message with {@code org.apache.log.Priority.DEBUG}. 237 * 238 * @param message to log 239 * @see org.apache.commons.logging.Log#trace(Object) 240 */ 241 @Override 242 public void trace(final Object message) { 243 debug(message); 244 } 245 246 /** 247 * Logs a message with {@code org.apache.log.Priority.DEBUG}. 248 * 249 * @param message to log 250 * @param t log this cause 251 * @see org.apache.commons.logging.Log#trace(Object, Throwable) 252 */ 253 @Override 254 public void trace(final Object message, final Throwable t) { 255 debug(message, t); 256 } 257 258 /** 259 * Logs a message with {@code org.apache.log.Priority.WARN}. 260 * 261 * @param message to log 262 * @see org.apache.commons.logging.Log#warn(Object) 263 */ 264 @Override 265 public void warn(final Object message) { 266 if (message != null) { 267 getLogger().warn(String.valueOf(message)); 268 } 269 } 270 271 /** 272 * Logs a message with {@code org.apache.log.Priority.WARN}. 273 * 274 * @param message to log 275 * @param t log this cause 276 * @see org.apache.commons.logging.Log#warn(Object, Throwable) 277 */ 278 @Override 279 public void warn(final Object message, final Throwable t) { 280 if (message != null) { 281 getLogger().warn(String.valueOf(message), t); 282 } 283 } 284 }