FELIX-2314: Improve logging support
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@939711 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/assembly/pom.xml b/karaf/assembly/pom.xml
index a5c6e91..b26ab29 100644
--- a/karaf/assembly/pom.xml
+++ b/karaf/assembly/pom.xml
@@ -53,6 +53,10 @@
</dependency>
<dependency>
<groupId>org.apache.felix.karaf</groupId>
+ <artifactId>org.apache.felix.karaf.exception</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix.karaf</groupId>
<artifactId>org.apache.felix.karaf.client</artifactId>
</dependency>
<dependency>
diff --git a/karaf/assembly/src/main/descriptors/unix-bin.xml b/karaf/assembly/src/main/descriptors/unix-bin.xml
index d148c48..35b2d63 100644
--- a/karaf/assembly/src/main/descriptors/unix-bin.xml
+++ b/karaf/assembly/src/main/descriptors/unix-bin.xml
@@ -128,6 +128,14 @@
</files>
<dependencySets>
+ <dependencySet>
+ <outputDirectory>/lib/endorsed</outputDirectory>
+ <unpack>false</unpack>
+ <useProjectArtifact>false</useProjectArtifact>
+ <includes>
+ <include>org.apache.felix.karaf:org.apache.felix.karaf.exception</include>
+ </includes>
+ </dependencySet>
<dependencySet>
<outputDirectory>/system</outputDirectory>
diff --git a/karaf/assembly/src/main/descriptors/windows-bin.xml b/karaf/assembly/src/main/descriptors/windows-bin.xml
index 995eed1..6e5a5f2 100644
--- a/karaf/assembly/src/main/descriptors/windows-bin.xml
+++ b/karaf/assembly/src/main/descriptors/windows-bin.xml
@@ -120,6 +120,14 @@
</files>
<dependencySets>
+ <dependencySet>
+ <outputDirectory>/lib/endorsed</outputDirectory>
+ <unpack>false</unpack>
+ <useProjectArtifact>false</useProjectArtifact>
+ <includes>
+ <include>org.apache.felix.karaf:org.apache.felix.karaf.exception</include>
+ </includes>
+ </dependencySet>
<dependencySet>
<outputDirectory>/system</outputDirectory>
diff --git a/karaf/assembly/src/main/distribution/text/etc/org.ops4j.pax.logging.cfg b/karaf/assembly/src/main/distribution/text/etc/org.ops4j.pax.logging.cfg
index 95bb4c2..7c1f73d 100644
--- a/karaf/assembly/src/main/distribution/text/etc/org.ops4j.pax.logging.cfg
+++ b/karaf/assembly/src/main/distribution/text/etc/org.ops4j.pax.logging.cfg
@@ -19,15 +19,27 @@
# Root logger
log4j.rootLogger=INFO, out, osgi:VmLogAppender
+log4j.throwableRenderer=org.apache.log4j.OsgiThrowableRenderer
# CONSOLE appender not used by default
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %m%n
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
# File appender
log4j.appender.out=org.apache.log4j.FileAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %m%n
+log4j.appender.out.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
log4j.appender.out.file=${karaf.base}/data/log/karaf.log
log4j.appender.out.append=true
+
+# Sift appender
+log4j.appender.sift=org.apache.log4j.sift.MDCSiftingAppender
+log4j.appender.sift.key=bundle.name
+log4j.appender.sift.default=karaf
+log4j.appender.sift.appender=org.apache.log4j.FileAppender
+log4j.appender.sift.appender.layout=org.apache.log4j.PatternLayout
+log4j.appender.sift.appender.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %m%n
+log4j.appender.sift.appender.file=${karaf.base}/data/log/$\\{bundle.name\\}.log
+log4j.appender.sift.appender.append=true
+
diff --git a/karaf/exception/pom.xml b/karaf/exception/pom.xml
new file mode 100644
index 0000000..f37a380
--- /dev/null
+++ b/karaf/exception/pom.xml
@@ -0,0 +1,38 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <!--
+
+ 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.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.felix.karaf</groupId>
+ <artifactId>karaf</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.felix.karaf</groupId>
+ <artifactId>org.apache.felix.karaf.exception</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ <name>Apache Felix Karaf :: Exception</name>
+
+ <properties>
+ <appendedResourcesDirectory>${basedir}/../etc/appended-resources</appendedResourcesDirectory>
+ </properties>
+
+</project>
diff --git a/karaf/exception/src/main/java/java/lang/Exception.java b/karaf/exception/src/main/java/java/lang/Exception.java
new file mode 100644
index 0000000..1aff70e
--- /dev/null
+++ b/karaf/exception/src/main/java/java/lang/Exception.java
@@ -0,0 +1,109 @@
+/*
+ * 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 java.lang;
+
+
+/**
+ * {@code Exception} is the superclass of all classes that represent recoverable
+ * exceptions. When exceptions are thrown, they may be caught by application
+ * code.
+ *
+ * @see Throwable
+ * @see Error
+ * @see RuntimeException
+ */
+public class Exception extends Throwable {
+ private static final long serialVersionUID = -3387516993124229948L;
+
+ private transient Class[] classContext = sm.getThrowableContext(this);
+
+ /**
+ * Constructs a new {@code Exception} that includes the current stack trace.
+ */
+ public Exception() {
+ super();
+ }
+
+ /**
+ * Constructs a new {@code Exception} with the current stack trace and the
+ * specified detail message.
+ *
+ * @param detailMessage
+ * the detail message for this exception.
+ */
+ public Exception(String detailMessage) {
+ super(detailMessage);
+ }
+
+ /**
+ * Constructs a new {@code Exception} with the current stack trace, the
+ * specified detail message and the specified cause.
+ *
+ * @param detailMessage
+ * the detail message for this exception.
+ * @param throwable
+ * the cause of this exception.
+ */
+ public Exception(String detailMessage, Throwable throwable) {
+ super(detailMessage, throwable);
+ }
+
+ /**
+ * Constructs a new {@code Exception} with the current stack trace and the
+ * specified cause.
+ *
+ * @param throwable
+ * the cause of this exception.
+ */
+ public Exception(Throwable throwable) {
+ super(throwable);
+ }
+
+ public Class[] getClassContext() {
+ return classContext;
+ }
+
+ private static final SecurityManagerEx sm = new SecurityManagerEx();
+
+ static class SecurityManagerEx extends SecurityManager
+ {
+ public Class[] getClassContext()
+ {
+ return super.getClassContext();
+ }
+
+ public Class[] getThrowableContext(Throwable t) {
+ try {
+ Class[] context = getClassContext();
+ int nb = 0;
+ for (;;) {
+ if (context[context.length - 1 - nb] == t.getClass()) {
+ break;
+ }
+ nb++;
+ }
+ Class[] nc = new Class[nb];
+ System.arraycopy(context, context.length - nb, nc, 0, nb);
+ return nc;
+ } catch (Exception e) {
+ return null;
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/karaf/pom.xml b/karaf/pom.xml
index 4080c21..09d3404 100644
--- a/karaf/pom.xml
+++ b/karaf/pom.xml
@@ -45,6 +45,7 @@
<module>management</module>
<module>webconsole</module>
<module>manual</module>
+ <module>exception</module>
<module>assembly</module>
<module>demos</module>
<module>itests</module>
@@ -91,11 +92,11 @@
<jetty.bundle.version>6.1.22_1</jetty.bundle.version>
<junit.version>4.7_1</junit.version>
<jline.version>0.9.95.20100209</jline.version>
- <log4j.version>1.2.14</log4j.version>
+ <log4j.version>1.2.16</log4j.version>
<maven.version>2.0.9</maven.version>
<mina.version>2.0.0-RC1</mina.version>
<pax.exam.version>1.1.0</pax.exam.version>
- <pax.logging.version>1.4</pax.logging.version>
+ <pax.logging.version>1.4.1-SNAPSHOT</pax.logging.version>
<pax.runner.version>1.2.1</pax.runner.version>
<pax.url.version>1.1.2</pax.url.version>
<pax.web.version>0.7.2</pax.web.version>
@@ -168,6 +169,11 @@
</dependency>
<dependency>
<groupId>org.apache.felix.karaf</groupId>
+ <artifactId>org.apache.felix.karaf.exception</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix.karaf</groupId>
<artifactId>org.apache.felix.karaf.client</artifactId>
<version>${pom.version}</version>
</dependency>