The version of Apache log4j used by SoundHelix.
Clone
HTTPS:
git clone https://vervis.peers.community/repos/aEp6o
SSH:
git clone USERNAME@vervis.peers.community:aEp6o
Branches
Tags
- 1.3alpha-7
- CHAINSAW_2_SANDBOX_MERGE
- CORE_VERSION
- LEVEL_REPLACES_PRIORITY
- PREALPHA_1_3_AS_OF_2004_05_12
- PRE_CHAINSAW_MODEL_CONVERSION
- PRE_UGLI_MOVE
- TAG_CHAINSAW2_MOVE
- log4j-1.2.17
- log4j-1.2.17-rc1
- v1.3alpha8
- v1.3alpha8-temp
- v1_2_1
- v1_2_10-recalled
- v1_2_11
- v1_2_11_rc1
- v1_2_11rc3
- v1_2_12
- v1_2_12_rc1
- v1_2_12_rc2
- v1_2_12_rc3
- v1_2_12_rc4
- v1_2_12_rc5
- v1_2_12_rc6
- v1_2_13
- v1_2_13_rc1
- v1_2_13_rc2
- v1_2_13_site_update
- v1_2_14
- v1_2_14_maven
- v1_2_14_rc1
- v1_2_14_site_update
- v1_2_15
- v1_2_15_rc1
- v1_2_15_rc2
- v1_2_15_rc3
- v1_2_15_rc4
- v1_2_15_rc5
- v1_2_15_rc6
- v1_2_16
- v1_2_16_rc1
- v1_2_16_rc2
- v1_2_17
- v1_2_17-rc1
- v1_2_17_rc1
- v1_2_17_rc2
- v1_2_17_rc3
- v1_2_2
- v1_2_3
- v1_2_4
- v1_2_6
- v1_2_7
- v1_2_9
- v1_2_alpha0
- v1_2_alpha7
- v1_2beta1
- v1_2final
- v1_3alpha_1
- v1_3alpha_6
- v_1_0
- v_1_0_1
- v_1_0_4
- v_1_1
- v_1_1_1
- v_1_1_2
- v_1_1_3
- v_1_1_b1
- v_1_1b2
- v_1_1b3
- v_1_1b5
- v_1_1b6
- v_1_1b7
- v_1_2beta3
EnhancedThrowableRenderer.java
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.log4j;
import org.apache.log4j.spi.ThrowableRenderer;
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.security.CodeSource;
import java.util.HashMap;
import java.util.Map;
/**
* Enhanced implementation of ThrowableRenderer. Uses Throwable.getStackTrace
* if running on JDK 1.4 or later and delegates to DefaultThrowableRenderer.render
* on earlier virtual machines.
*
* @since 1.2.16
*/
public final class EnhancedThrowableRenderer implements ThrowableRenderer {
/**
* Throwable.getStackTrace() method.
*/
private Method getStackTraceMethod;
/**
* StackTraceElement.getClassName() method.
*/
private Method getClassNameMethod;
/**
* Construct new instance.
*/
public EnhancedThrowableRenderer() {
try {
Class[] noArgs = null;
getStackTraceMethod = Throwable.class.getMethod("getStackTrace", noArgs);
Class ste = Class.forName("java.lang.StackTraceElement");
getClassNameMethod = ste.getMethod("getClassName", noArgs);
} catch(Exception ex) {
}
}
/**
* {@inheritDoc}
*/
public String[] doRender(final Throwable throwable) {
if (getStackTraceMethod != null) {
try {
Object[] noArgs = null;
Object[] elements = (Object[]) getStackTraceMethod.invoke(throwable, noArgs);
String[] lines = new String[elements.length + 1];
lines[0] = throwable.toString();
Map classMap = new HashMap();
for(int i = 0; i < elements.length; i++) {
lines[i+1] = formatElement(elements[i], classMap);
}
return lines;
} catch(Exception ex) {
}
}
return DefaultThrowableRenderer.render(throwable);
}
/**
* Format one element from stack trace.
* @param element element, may not be null.
* @param classMap map of class name to location.
* @return string representation of element.
*/
private String formatElement(final Object element, final Map classMap) {
StringBuffer buf = new StringBuffer("\tat ");
buf.append(element);
try {
String className = getClassNameMethod.invoke(element, (Object[]) null).toString();
Object classDetails = classMap.get(className);
if (classDetails != null) {
buf.append(classDetails);
} else {
Class cls = findClass(className);
int detailStart = buf.length();
buf.append('[');
try {
CodeSource source = cls.getProtectionDomain().getCodeSource();
if (source != null) {
URL locationURL = source.getLocation();
if (locationURL != null) {
//
// if a file: URL
//
if ("file".equals(locationURL.getProtocol())) {
String path = locationURL.getPath();
if (path != null) {
//
// find the last file separator character
//
int lastSlash = path.lastIndexOf('/');
int lastBack = path.lastIndexOf(File.separatorChar);
if (lastBack > lastSlash) {
lastSlash = lastBack;
}
//
// if no separator or ends with separator (a directory)
// then output the URL, otherwise just the file name.
//
if (lastSlash <= 0 || lastSlash == path.length() - 1) {
buf.append(locationURL);
} else {
buf.append(path.substring(lastSlash + 1));
}
}
} else {
buf.append(locationURL);
}
}
}
} catch(SecurityException ex) {
}
buf.append(':');
Package pkg = cls.getPackage();
if (pkg != null) {
String implVersion = pkg.getImplementationVersion();
if (implVersion != null) {
buf.append(implVersion);
}
}
buf.append(']');
classMap.put(className, buf.substring(detailStart));
}
} catch(Exception ex) {
}
return buf.toString();
}
/**
* Find class given class name.
* @param className class name, may not be null.
* @return class, will not be null.
* @throws ClassNotFoundException thrown if class can not be found.
*/
private Class findClass(final String className) throws ClassNotFoundException {
try {
return Thread.currentThread().getContextClassLoader().loadClass(className);
} catch (ClassNotFoundException e) {
try {
return Class.forName(className);
} catch (ClassNotFoundException e1) {
return getClass().getClassLoader().loadClass(className);
}
}
}
}