logging-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject svn commit: r693713 - in /logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw: ChainsawToolBarAndMenus.java CopyEventsToClipboardAction.java
Date Wed, 10 Sep 2008 06:23:53 GMT
Author: psmith
Date: Tue Sep  9 23:23:52 2008
New Revision: 693713

URL: http://svn.apache.org/viewvc?rev=693713&view=rev
Log:
Add a menu item that allows the user to copy the currently displayed events to the System
clipboard in a reasonable good human-readable format.

Quite good for QA people to paste into an issue tracker.


Added:
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/CopyEventsToClipboardAction.java
Modified:
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java?rev=693713&r1=693712&r2=693713&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java
Tue Sep  9 23:23:52 2008
@@ -103,7 +103,7 @@
   private final JMenuBar menuBar;
   private final JCheckBoxMenuItem menuItemClose = new JCheckBoxMenuItem();
   private final JToolBar toolbar;
-  private LogUI logui;
+  private final LogUI logui;
   private final SmallButton clearButton = new SmallButton();
   private final SmallToggleButton detailPaneButton = new SmallToggleButton();
   private final SmallToggleButton logTreePaneButton = new SmallToggleButton();
@@ -410,11 +410,13 @@
     activeTabMenu.add(menuPrefs);
 
     activeTabMenu.addSeparator();
+    activeTabMenu.add(new CopyEventsToClipboardAction(logui));
     activeTabMenu.add(new JMenuItem(clearAction));
     activeTabMenu.addSeparator();
     activeTabMenu.add(toggleScrollToBottomMenuItem);
     activeTabMenu.add(menuItemUseRightMouse);
 
+    
     viewMenu.add(showToolbarCheck);
     viewMenu.add(toggleStatusBarCheck);
     viewMenu.add(toggleShowReceiversCheck);

Added: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/CopyEventsToClipboardAction.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/CopyEventsToClipboardAction.java?rev=693713&view=auto
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/CopyEventsToClipboardAction.java
(added)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/CopyEventsToClipboardAction.java
Tue Sep  9 23:23:52 2008
@@ -0,0 +1,63 @@
+/*
+ * 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.chainsaw;
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.StringSelection;
+import java.awt.event.ActionEvent;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+
+import org.apache.log4j.EnhancedPatternLayout;
+import org.apache.log4j.Layout;
+import org.apache.log4j.spi.LoggingEvent;
+
+public class CopyEventsToClipboardAction extends AbstractAction {
+
+    private static final long serialVersionUID = 1L;
+    private static final int EVENTSIZE_FUDGE_FACTOR = 128; // guestimate 128 chars per event
+    private final LogUI logUi;
+
+    /**
+     * Layout pattern uses a simple but concise format that reads well and has a fixed size
set of
+     * useful columns before the message. Nice format for pasting into issue trackers.
+     */
+    private final Layout layout = new EnhancedPatternLayout(
+            "[%d{ISO8601} %-5p][%20.20c][%t] %m%n");
+
+    public CopyEventsToClipboardAction(LogUI parent) {
+        super("Copy events to clipboard");
+        this.logUi = parent;
+        layout.activateOptions();
+        
+        putValue(Action.SHORT_DESCRIPTION,
+                "Copies to the clipboard currently visible events to a human-readable, log-like
format");
+
+    }
+    
+    
+    public void actionPerformed(ActionEvent e) {
+        List filteredEvents = logUi.getCurrentLogPanel().getFilteredEvents();
+        StringBuffer writer = new StringBuffer(filteredEvents.size() * EVENTSIZE_FUDGE_FACTOR);
+        for (Iterator iterator = filteredEvents.iterator(); iterator.hasNext();) {
+            LoggingEvent event = (LoggingEvent) iterator.next();
+            writer.append(layout.format(event));
+        }
+
+        StringSelection stringSelection = new StringSelection(writer.toString());
+        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection,
+                stringSelection);
+    }
+
+}



Mime
View raw message