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.
18 package org.apache.log4j.spi;
20 import org.apache.log4j.Category;
21 import org.apache.log4j.DefaultThrowableRenderer;
24 * ThrowableInformation is log4j's internal representation of
25 * throwables. It essentially consists of a string array, called
26 * 'rep', where the first element, that is rep[0], represents the
27 * string representation of the throwable (i.e. the value you get
28 * when you do throwable.toString()) and subsequent elements
29 * correspond the stack trace with the top most entry of the stack
30 * corresponding to the second entry of the 'rep' array that is
33 * @author Ceki Gülcü
36 public class ThrowableInformation implements java.io.Serializable {
38 static final long serialVersionUID = -4748765566864322735L;
40 private transient Throwable throwable;
41 private transient Category category;
45 ThrowableInformation(Throwable throwable) {
46 this.throwable = throwable;
50 * Create a new instance.
51 * @param throwable throwable, may not be null.
52 * @param category category used to obtain ThrowableRenderer, may be null.
55 public ThrowableInformation(Throwable throwable, Category category) {
56 this.throwable = throwable;
57 this.category = category;
61 * Create new instance.
63 * @param r String representation of throwable.
65 public ThrowableInformation(final String[] r) {
67 rep = (String[]) r.clone();
73 Throwable getThrowable() {
77 public synchronized String[] getThrowableStrRep() {
79 ThrowableRenderer renderer = null;
80 if (category != null) {
81 LoggerRepository repo = category.getLoggerRepository();
82 if (repo instanceof ThrowableRendererSupport) {
83 renderer = ((ThrowableRendererSupport) repo).getThrowableRenderer();
86 if (renderer == null) {
87 rep = DefaultThrowableRenderer.render(throwable);
89 rep = renderer.doRender(throwable);
92 return (String[]) rep.clone();