You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/10/02 04:06:47 UTC

svn commit: r700988 - in /servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main: java/org/apache/servicemix/gshell/log/DisplayException.java resources/META-INF/spring/gshell-log.xml

Author: gnodet
Date: Wed Oct  1 19:06:47 2008
New Revision: 700988

URL: http://svn.apache.org/viewvc?rev=700988&view=rev
Log:
SMX4KNL-108: add a new 'log de' command to display the last exception from the log

Added:
    servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main/java/org/apache/servicemix/gshell/log/DisplayException.java
Modified:
    servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main/resources/META-INF/spring/gshell-log.xml

Added: servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main/java/org/apache/servicemix/gshell/log/DisplayException.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main/java/org/apache/servicemix/gshell/log/DisplayException.java?rev=700988&view=auto
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main/java/org/apache/servicemix/gshell/log/DisplayException.java (added)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main/java/org/apache/servicemix/gshell/log/DisplayException.java Wed Oct  1 19:06:47 2008
@@ -0,0 +1,61 @@
+/*
+ * 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.servicemix.gshell.log;
+
+import org.apache.geronimo.gshell.command.annotation.CommandComponent;
+import org.apache.geronimo.gshell.support.OsgiCommandSupport;
+import org.ops4j.pax.logging.spi.PaxLoggingEvent;
+
+@CommandComponent(id = "log:display-exception", description = "Display last exception in the log")
+public class DisplayException extends OsgiCommandSupport {
+
+    protected LruList<PaxLoggingEvent> events;
+
+    @Override
+    protected OsgiCommandSupport createCommand() throws Exception {
+        DisplayException command = new DisplayException();
+        command.setEvents(getEvents());
+        return command;
+    }
+
+    public LruList<PaxLoggingEvent> getEvents() {
+        return events;
+    }
+
+    public void setEvents(LruList<PaxLoggingEvent> events) {
+        this.events = events;
+    }
+
+    protected Object doExecute() throws Exception {
+        PaxLoggingEvent throwableEvent = null;
+        Iterable<PaxLoggingEvent> le = events.getElements(Integer.MAX_VALUE);
+        for (PaxLoggingEvent event : le) {
+            if (event.getThrowableStrRep() != null) {
+                throwableEvent = event;
+                // Do not break, as we iterate from the oldest to the newest event
+            }
+        }
+        if (throwableEvent != null) {
+            for (String r : throwableEvent.getThrowableStrRep()) {
+                io.out.println(r);
+            }
+            io.out.println();
+        }
+        return SUCCESS;
+    }
+
+}

Modified: servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main/resources/META-INF/spring/gshell-log.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main/resources/META-INF/spring/gshell-log.xml?rev=700988&r1=700987&r2=700988&view=diff
==============================================================================
--- servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main/resources/META-INF/spring/gshell-log.xml (original)
+++ servicemix/smx4/kernel/trunk/gshell/gshell-log/src/main/resources/META-INF/spring/gshell-log.xml Wed Oct  1 19:06:47 2008
@@ -37,6 +37,10 @@
         <property name="pattern" value="${pattern}" />
     </bean>
 
+    <bean id="display-exception" class="org.apache.servicemix.gshell.log.DisplayException">
+        <property name="events" ref="events" />
+    </bean>
+
     <bean id="get-log-level" class="org.apache.servicemix.gshell.log.GetLogLevel" />
 
     <bean id="set-log-level" class="org.apache.servicemix.gshell.log.SetLogLevel" />
@@ -57,6 +61,13 @@
       </osgi:service-properties>
     </osgi:service>
 
+    <osgi:service ref="display-exception" interface="org.apache.geronimo.gshell.command.Command">
+      <osgi:service-properties>
+        <entry key="shell" value="log"/>
+        <entry key="alias" value="de"/>
+      </osgi:service-properties>
+    </osgi:service>
+
     <osgi:service ref="get-log-level" interface="org.apache.geronimo.gshell.command.Command">
       <osgi:service-properties>
         <entry key="shell" value="log"/>