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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.apache.log4j;
19 import org.apache.log4j.spi.LoggingEvent;
22 * This is a base class for LogMF and LogSF parameterized logging classes.
25 * @see org.apache.log4j.LogMF
26 * @see org.apache.log4j.LogSF
29 public abstract class LogXF {
33 protected static final Level TRACE = new Level(5000, "TRACE", 7);
35 * Fully Qualified Class Name of this class.
37 private static final String FQCN = LogXF.class.getName();
43 * Returns a Boolean instance representing the specified boolean.
44 * Boolean.valueOf was added in JDK 1.4.
46 * @param b a boolean value.
47 * @return a Boolean instance representing b.
49 protected static Boolean valueOf(final boolean b) {
57 * Returns a Character instance representing the specified char.
58 * Character.valueOf was added in JDK 1.5.
60 * @param c a character value.
61 * @return a Character instance representing c.
63 protected static Character valueOf(final char c) {
64 return new Character(c);
68 * Returns a Byte instance representing the specified byte.
69 * Byte.valueOf was added in JDK 1.5.
71 * @param b a byte value.
72 * @return a Byte instance representing b.
74 protected static Byte valueOf(final byte b) {
79 * Returns a Short instance representing the specified short.
80 * Short.valueOf was added in JDK 1.5.
82 * @param b a short value.
83 * @return a Byte instance representing b.
85 protected static Short valueOf(final short b) {
90 * Returns an Integer instance representing the specified int.
91 * Integer.valueOf was added in JDK 1.5.
93 * @param b an int value.
94 * @return an Integer instance representing b.
96 protected static Integer valueOf(final int b) {
97 return new Integer(b);
101 * Returns a Long instance representing the specified long.
102 * Long.valueOf was added in JDK 1.5.
104 * @param b a long value.
105 * @return a Long instance representing b.
107 protected static Long valueOf(final long b) {
112 * Returns a Float instance representing the specified float.
113 * Float.valueOf was added in JDK 1.5.
115 * @param b a float value.
116 * @return a Float instance representing b.
118 protected static Float valueOf(final float b) {
123 * Returns a Double instance representing the specified double.
124 * Double.valueOf was added in JDK 1.5.
126 * @param b a double value.
127 * @return a Byte instance representing b.
129 protected static Double valueOf(final double b) {
130 return new Double(b);
136 * @param param1 parameter 1.
139 protected static Object[] toArray(final Object param1) {
148 * @param param1 parameter 1.
149 * @param param2 parameter 2.
152 protected static Object[] toArray(final Object param1,
153 final Object param2) {
162 * @param param1 parameter 1.
163 * @param param2 parameter 2.
164 * @param param3 parameter 3.
167 protected static Object[] toArray(final Object param1,
169 final Object param3) {
171 param1, param2, param3
178 * @param param1 parameter 1.
179 * @param param2 parameter 2.
180 * @param param3 parameter 3.
181 * @param param4 parameter 4.
184 protected static Object[] toArray(final Object param1,
187 final Object param4) {
189 param1, param2, param3, param4
194 * Log an entering message at DEBUG level.
196 * @param logger logger, may not be null.
197 * @param sourceClass source class, may be null.
198 * @param sourceMethod method, may be null.
200 public static void entering(final Logger logger,
201 final String sourceClass,
202 final String sourceMethod) {
203 if (logger.isDebugEnabled()) {
204 logger.callAppenders(new LoggingEvent(FQCN, logger, Level.DEBUG,
205 sourceClass + "." + sourceMethod + " ENTRY", null));
210 * Log an entering message with a parameter at DEBUG level.
212 * @param logger logger, may not be null.
213 * @param sourceClass source class, may be null.
214 * @param sourceMethod method, may be null.
215 * @param param parameter, may be null.
217 public static void entering(final Logger logger,
218 final String sourceClass,
219 final String sourceMethod,
220 final String param) {
221 if (logger.isDebugEnabled()) {
222 String msg = sourceClass + "." + sourceMethod + " ENTRY " + param;
223 logger.callAppenders(new LoggingEvent(FQCN, logger, Level.DEBUG,
229 * Log an entering message with a parameter at DEBUG level.
231 * @param logger logger, may not be null.
232 * @param sourceClass source class, may be null.
233 * @param sourceMethod method, may be null.
234 * @param param parameter, may be null.
236 public static void entering(final Logger logger,
237 final String sourceClass,
238 final String sourceMethod,
239 final Object param) {
240 if (logger.isDebugEnabled()) {
241 String msg = sourceClass + "." + sourceMethod + " ENTRY ";
247 } catch(Throwable ex) {
251 logger.callAppenders(new LoggingEvent(FQCN, logger, Level.DEBUG,
257 * Log an entering message with an array of parameters at DEBUG level.
259 * @param logger logger, may not be null.
260 * @param sourceClass source class, may be null.
261 * @param sourceMethod method, may be null.
262 * @param params parameters, may be null.
264 public static void entering(final Logger logger,
265 final String sourceClass,
266 final String sourceMethod,
267 final Object[] params) {
268 if (logger.isDebugEnabled()) {
269 String msg = sourceClass + "." + sourceMethod + " ENTRY ";
270 if (params != null && params.length > 0) {
272 for (int i = 0; i < params.length; i++) {
274 msg += delim + params[i];
275 } catch(Throwable ex) {
284 logger.callAppenders(new LoggingEvent(FQCN, logger, Level.DEBUG,
290 * Log an exiting message at DEBUG level.
292 * @param logger logger, may not be null.
293 * @param sourceClass source class, may be null.
294 * @param sourceMethod method, may be null.
296 public static void exiting(final Logger logger,
297 final String sourceClass,
298 final String sourceMethod) {
299 if (logger.isDebugEnabled()) {
300 logger.callAppenders(new LoggingEvent(FQCN, logger, Level.DEBUG,
301 sourceClass + "." + sourceMethod + " RETURN", null));
306 * Log an exiting message with result at DEBUG level.
308 * @param logger logger, may not be null.
309 * @param sourceClass source class, may be null.
310 * @param sourceMethod method, may be null.
311 * @param result result, may be null.
313 public static void exiting(
315 final String sourceClass,
316 final String sourceMethod,
317 final String result) {
318 if (logger.isDebugEnabled()) {
319 logger.callAppenders(new LoggingEvent(FQCN, logger, Level.DEBUG,
320 sourceClass + "." + sourceMethod + " RETURN " + result, null));
325 * Log an exiting message with result at DEBUG level.
327 * @param logger logger, may not be null.
328 * @param sourceClass source class, may be null.
329 * @param sourceMethod method, may be null.
330 * @param result result, may be null.
332 public static void exiting(
334 final String sourceClass,
335 final String sourceMethod,
336 final Object result) {
337 if (logger.isDebugEnabled()) {
338 String msg = sourceClass + "." + sourceMethod + " RETURN ";
339 if (result == null) {
344 } catch(Throwable ex) {
348 logger.callAppenders(new LoggingEvent(FQCN, logger, Level.DEBUG,
354 * Logs a throwing message at DEBUG level.
356 * @param logger logger, may not be null.
357 * @param sourceClass source class, may be null.
358 * @param sourceMethod method, may be null.
359 * @param thrown throwable, may be null.
361 public static void throwing(
363 final String sourceClass,
364 final String sourceMethod,
365 final Throwable thrown) {
366 if (logger.isDebugEnabled()) {
367 logger.callAppenders(new LoggingEvent(FQCN, logger, Level.DEBUG,
368 sourceClass + "." + sourceMethod + " THROW", thrown));