You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ow...@apache.org on 2013/06/04 18:03:28 UTC
svn commit: r1489492 - in
/cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event:
LoggerListener.java StacktraceDefaultFormatter.java
StacktraceFormatter.java StacktraceHtmlFormatter.java
Author: owulff
Date: Tue Jun 4 16:03:27 2013
New Revision: 1489492
URL: http://svn.apache.org/r1489492
Log:
Stacktrace format customizable in LoggerListener
Added:
cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/StacktraceDefaultFormatter.java
cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/StacktraceFormatter.java
cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/StacktraceHtmlFormatter.java
Modified:
cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/LoggerListener.java
Modified: cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/LoggerListener.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/LoggerListener.java?rev=1489492&r1=1489491&r2=1489492&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/LoggerListener.java (original)
+++ cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/LoggerListener.java Tue Jun 4 16:03:27 2013
@@ -19,9 +19,6 @@
package org.apache.cxf.sts.event;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.io.Writer;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -66,7 +63,8 @@ public class LoggerListener implements A
RENEW_PRINCIPAL,
REMOTE_HOST,
REMOTE_PORT,
- URL
+ URL,
+ STACKTRACE
};
private static final Logger LOG = LogUtils.getL7dLogger(LoggerListener.class);
@@ -76,7 +74,10 @@ public class LoggerListener implements A
private boolean logFieldname;
private Level logLevel = Level.FINE;
private DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
+ private StacktraceFormatter stacktraceFormatter = new StacktraceDefaultFormatter();
+
+
public LoggerListener() {
fieldOrder.add(KEYS.TIME.name());
fieldOrder.add(KEYS.STATUS.name());
@@ -97,6 +98,7 @@ public class LoggerListener implements A
fieldOrder.add(KEYS.CLAIMS_PRIMARY.name());
fieldOrder.add(KEYS.CLAIMS_SECONDARY.name());
fieldOrder.add(KEYS.EXCEPTION.name());
+ fieldOrder.add(KEYS.STACKTRACE.name());
}
@Override
@@ -181,13 +183,9 @@ public class LoggerListener implements A
if (event instanceof AbstractSTSFailureEvent) {
map.put(KEYS.STATUS.name(), "FAILURE");
Exception ex = ((AbstractSTSFailureEvent)event).getException();
- if (this.isLogStacktrace()) {
- final Writer result = new StringWriter();
- final PrintWriter printWriter = new PrintWriter(result);
- ex.printStackTrace(printWriter);
- map.put(KEYS.EXCEPTION.name(), result.toString());
- } else {
- map.put(KEYS.EXCEPTION.name(), ex.getMessage());
+ map.put(KEYS.EXCEPTION.name(), ex.getMessage());
+ if (this.isLogStacktrace() && stacktraceFormatter != null) {
+ map.put(KEYS.STACKTRACE.name(), stacktraceFormatter.format(ex));
}
} else {
map.put(KEYS.STATUS.name(), "SUCCESS");
@@ -226,13 +224,9 @@ public class LoggerListener implements A
if (event instanceof AbstractSTSFailureEvent) {
map.put(KEYS.STATUS.name(), "FAILURE");
Exception ex = ((AbstractSTSFailureEvent)event).getException();
- if (this.isLogStacktrace()) {
- final Writer result = new StringWriter();
- final PrintWriter printWriter = new PrintWriter(result);
- ex.printStackTrace(printWriter);
- map.put(KEYS.EXCEPTION.name(), result.toString());
- } else {
- map.put(KEYS.EXCEPTION.name(), ex.getMessage());
+ map.put(KEYS.EXCEPTION.name(), ex.getMessage());
+ if (this.isLogStacktrace() && stacktraceFormatter != null) {
+ map.put(KEYS.STACKTRACE.name(), stacktraceFormatter.format(ex));
}
} else {
map.put(KEYS.STATUS.name(), "SUCCESS");
@@ -271,13 +265,9 @@ public class LoggerListener implements A
if (event instanceof AbstractSTSFailureEvent) {
map.put(KEYS.STATUS.name(), "FAILURE");
Exception ex = ((AbstractSTSFailureEvent)event).getException();
- if (this.isLogStacktrace()) {
- final Writer result = new StringWriter();
- final PrintWriter printWriter = new PrintWriter(result);
- ex.printStackTrace(printWriter);
- map.put(KEYS.EXCEPTION.name(), result.toString());
- } else {
- map.put(KEYS.EXCEPTION.name(), ex.getMessage());
+ map.put(KEYS.EXCEPTION.name(), ex.getMessage());
+ if (this.isLogStacktrace() && stacktraceFormatter != null) {
+ map.put(KEYS.STACKTRACE.name(), stacktraceFormatter.format(ex));
}
} else {
map.put(KEYS.STATUS.name(), "SUCCESS");
@@ -316,13 +306,9 @@ public class LoggerListener implements A
if (event instanceof AbstractSTSFailureEvent) {
map.put(KEYS.STATUS.name(), "FAILURE");
Exception ex = ((AbstractSTSFailureEvent)event).getException();
- if (this.isLogStacktrace()) {
- final Writer result = new StringWriter();
- final PrintWriter printWriter = new PrintWriter(result);
- ex.printStackTrace(printWriter);
- map.put(KEYS.EXCEPTION.name(), result.toString());
- } else {
- map.put(KEYS.EXCEPTION.name(), ex.getMessage());
+ map.put(KEYS.EXCEPTION.name(), ex.getMessage());
+ if (this.isLogStacktrace() && stacktraceFormatter != null) {
+ map.put(KEYS.STACKTRACE.name(), stacktraceFormatter.format(ex));
}
} else {
map.put(KEYS.STATUS.name(), "SUCCESS");
@@ -382,4 +368,12 @@ public class LoggerListener implements A
this.logLevel = Level.parse(logLevel);
}
+ public StacktraceFormatter getStacktraceFormatter() {
+ return stacktraceFormatter;
+ }
+
+ public void setStacktraceFormatter(StacktraceFormatter stacktraceFormatter) {
+ this.stacktraceFormatter = stacktraceFormatter;
+ }
+
}
Added: cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/StacktraceDefaultFormatter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/StacktraceDefaultFormatter.java?rev=1489492&view=auto
==============================================================================
--- cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/StacktraceDefaultFormatter.java (added)
+++ cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/StacktraceDefaultFormatter.java Tue Jun 4 16:03:27 2013
@@ -0,0 +1,37 @@
+/**
+ * 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.cxf.sts.event;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+
+public class StacktraceDefaultFormatter implements StacktraceFormatter {
+
+ @Override
+ public String format(Throwable t) {
+ final Writer result = new StringWriter();
+ t.printStackTrace(new PrintWriter(result));
+ return result.toString();
+ }
+
+}
+
+
Added: cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/StacktraceFormatter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/StacktraceFormatter.java?rev=1489492&view=auto
==============================================================================
--- cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/StacktraceFormatter.java (added)
+++ cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/StacktraceFormatter.java Tue Jun 4 16:03:27 2013
@@ -0,0 +1,24 @@
+/**
+ * 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.cxf.sts.event;
+
+public interface StacktraceFormatter {
+ String format(Throwable t);
+}
Added: cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/StacktraceHtmlFormatter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/StacktraceHtmlFormatter.java?rev=1489492&view=auto
==============================================================================
--- cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/StacktraceHtmlFormatter.java (added)
+++ cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/event/StacktraceHtmlFormatter.java Tue Jun 4 16:03:27 2013
@@ -0,0 +1,40 @@
+/**
+ * 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.cxf.sts.event;
+
+public class StacktraceHtmlFormatter implements StacktraceFormatter {
+
+ public static final String NEW_LINE = "<br>";
+
+ @Override
+ public String format(Throwable t) {
+ final StringBuilder result = new StringBuilder("<html>");
+ result.append(t.toString());
+ result.append(NEW_LINE);
+
+ for (StackTraceElement element : t.getStackTrace()) {
+ result.append(element);
+ result.append(NEW_LINE);
+ }
+ result.append("</html>");
+ return result.toString();
+ }
+
+}