logging-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sde...@apache.org
Subject svn commit: r930482 - in /logging/chainsaw/trunk/src/main: java/org/apache/log4j/chainsaw/ resources/org/apache/log4j/chainsaw/help/
Date Sat, 03 Apr 2010 06:19:05 GMT
Author: sdeboy
Date: Sat Apr  3 06:19:05 2010
New Revision: 930482

URL: http://svn.apache.org/viewvc?rev=930482&view=rev
Log:
If the file-save as menu is provided a file ending in .zip, a zip file will be created containing
an xml file of the event contents.

Fixed a minor bug in the goto-line logic preventing line navigation if a loaded file's rows
did not start at 1.

Modified:
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/FileSaveAction.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java
    logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/help/release-notes.html

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/FileSaveAction.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/FileSaveAction.java?rev=930482&r1=930481&r2=930482&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/FileSaveAction.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/FileSaveAction.java Sat
Apr  3 06:19:05 2010
@@ -20,13 +20,18 @@ package org.apache.log4j.chainsaw;
 import java.awt.event.ActionEvent;
 import java.awt.event.InputEvent;
 import java.awt.event.KeyEvent;
+import java.io.BufferedOutputStream;
 import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.io.PrintWriter;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
 import java.util.Iterator;
 import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
 
 import javax.swing.AbstractAction;
 import javax.swing.Action;
@@ -35,6 +40,7 @@ import javax.swing.JFileChooser;
 import javax.swing.KeyStroke;
 
 import org.apache.log4j.chainsaw.icons.ChainsawIcons;
+import org.apache.log4j.helpers.LogLog;
 import org.apache.log4j.spi.LoggingEvent;
 import org.apache.log4j.xml.XMLLayout;
 
@@ -87,38 +93,47 @@ class FileSaveAction extends AbstractAct
     chooser.showSaveDialog(parent);
 
     File selectedFile = chooser.getSelectedFile();
-    XMLLayout layout = new XMLLayout();
-    layout.setProperties(true);
-    LoggingEvent event = null;
-    PrintWriter out = null;
 
     if (selectedFile != null) {
-      try {
-        List v = parent.getCurrentLogPanel().getFilteredEvents();
+    List v = parent.getCurrentLogPanel().getFilteredEvents();
 
-        if (((v != null) && (v.size() == 0)) || (v == null)) {
-          //no events to save
-          return;
-        }
-
-        Iterator iter = v.iterator();
-
-        out =
-          new PrintWriter(new BufferedWriter(new FileWriter(selectedFile)));
-
-        while (iter.hasNext()) {
-          event = (LoggingEvent) iter.next();
-          layout.setLocationInfo(event.getThrowableInformation() != null);
-          out.write(layout.format(event));
-        }
-      } catch (IOException ioe) {
-        ioe.printStackTrace();
-      } finally {
-        if (out != null) {
-          out.flush();
-          out.close();
-        }
+    if (((v != null) && (v.size() == 0)) || (v == null)) {
+      //no events to save
+      return;
+    }
+
+    XMLLayout layout = new XMLLayout();
+    layout.setProperties(true);
+    boolean saveAsZip = selectedFile.getName().toLowerCase().endsWith(".zip");
+    Writer writer = null;
+    try {
+      if (saveAsZip) {
+          ZipOutputStream zipOutput = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(selectedFile)));
+          ZipEntry entry = new ZipEntry(selectedFile.getName().substring(0, selectedFile.getName().length()
- ".zip".length()) + ".xml");
+          zipOutput.putNextEntry(entry);
+          writer = new OutputStreamWriter(zipOutput);
+      } else {
+          writer = new BufferedWriter(new FileWriter(selectedFile));
+      }
+      Iterator iter = v.iterator();
+      while (iter.hasNext()) {
+        LoggingEvent event = (LoggingEvent) iter.next();
+        layout.setLocationInfo(event.getThrowableInformation() != null);
+        writer.write(layout.format(event));
+      }
+    } catch (IOException ioe) {
+      LogLog.warn("Unable to save file", ioe);
+    } finally {
+      if (writer != null) {
+          try {
+              writer.flush();
+              writer.close();
+          }
+          catch (IOException e1) {
+              //ignore
+          }
       }
     }
   }
+  }
 }

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java?rev=930482&r1=930481&r2=930482&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java Sat Apr 
3 06:19:05 2010
@@ -205,8 +205,7 @@ import com.thoughtworks.xstream.io.xml.D
  *@author Isuru Suriarachchi
  *
  */
-public class LogPanel extends DockablePanel implements EventBatchListener,
-  Profileable {
+public class LogPanel extends DockablePanel implements EventBatchListener, Profileable {
   private static final double DEFAULT_DETAIL_SPLIT_LOCATION = 0.56d;
   private static final double DEFAULT_LOG_TREE_SPLIT_LOCATION = 0.2d;
   private final String identifier;
@@ -277,28 +276,16 @@ public class LogPanel extends DockablePa
     findPanel.setMinimumSize(findPanelSize);
 
     final Map columnNameKeywordMap = new HashMap();
-    columnNameKeywordMap.put(
-      ChainsawConstants.CLASS_COL_NAME, LoggingEventFieldResolver.CLASS_FIELD);
-    columnNameKeywordMap.put(
-      ChainsawConstants.FILE_COL_NAME, LoggingEventFieldResolver.FILE_FIELD);
-    columnNameKeywordMap.put(
-      ChainsawConstants.LEVEL_COL_NAME, LoggingEventFieldResolver.LEVEL_FIELD);
-    columnNameKeywordMap.put(
-      ChainsawConstants.LINE_COL_NAME, LoggingEventFieldResolver.LINE_FIELD);
-    columnNameKeywordMap.put(
-      ChainsawConstants.LOGGER_COL_NAME, LoggingEventFieldResolver.LOGGER_FIELD);
-    columnNameKeywordMap.put(
-      ChainsawConstants.NDC_COL_NAME, LoggingEventFieldResolver.NDC_FIELD);
-    columnNameKeywordMap.put(
-      ChainsawConstants.MESSAGE_COL_NAME, LoggingEventFieldResolver.MSG_FIELD);
-    columnNameKeywordMap.put(
-      ChainsawConstants.THREAD_COL_NAME, LoggingEventFieldResolver.THREAD_FIELD);
-    columnNameKeywordMap.put(
-      ChainsawConstants.THROWABLE_COL_NAME,
-      LoggingEventFieldResolver.EXCEPTION_FIELD);
-    columnNameKeywordMap.put(
-      ChainsawConstants.TIMESTAMP_COL_NAME,
-      LoggingEventFieldResolver.TIMESTAMP_FIELD);
+    columnNameKeywordMap.put(ChainsawConstants.CLASS_COL_NAME, LoggingEventFieldResolver.CLASS_FIELD);
+    columnNameKeywordMap.put(ChainsawConstants.FILE_COL_NAME, LoggingEventFieldResolver.FILE_FIELD);
+    columnNameKeywordMap.put(ChainsawConstants.LEVEL_COL_NAME, LoggingEventFieldResolver.LEVEL_FIELD);
+    columnNameKeywordMap.put(ChainsawConstants.LINE_COL_NAME, LoggingEventFieldResolver.LINE_FIELD);
+    columnNameKeywordMap.put(ChainsawConstants.LOGGER_COL_NAME, LoggingEventFieldResolver.LOGGER_FIELD);
+    columnNameKeywordMap.put(ChainsawConstants.NDC_COL_NAME, LoggingEventFieldResolver.NDC_FIELD);
+    columnNameKeywordMap.put(ChainsawConstants.MESSAGE_COL_NAME, LoggingEventFieldResolver.MSG_FIELD);
+    columnNameKeywordMap.put(ChainsawConstants.THREAD_COL_NAME, LoggingEventFieldResolver.THREAD_FIELD);
+    columnNameKeywordMap.put(ChainsawConstants.THROWABLE_COL_NAME, LoggingEventFieldResolver.EXCEPTION_FIELD);
+    columnNameKeywordMap.put(ChainsawConstants.TIMESTAMP_COL_NAME, LoggingEventFieldResolver.TIMESTAMP_FIELD);
 
     preferencesFrame.setTitle("'" + identifier + "' Log Panel Preferences");
     preferencesFrame.setIconImage(
@@ -1969,10 +1956,14 @@ public class LogPanel extends DockablePa
    * Change the selected event on the log panel
    *
    * @param eventNumber
+   * @return row number or -1 if row with log4jid property with that number was not found
    */
-  void setSelectedEvent(int eventNumber) {
+  int setSelectedEvent(int eventNumber) {
       int row = tableModel.find(ExpressionRule.getRule("prop.log4jid == " + eventNumber),
0, true);
-      table.scrollTo(row, 0);
+      if (row > -1) {
+        table.scrollTo(row, 0);
+      }
+      return row;
   }
 
   /**

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java?rev=930482&r1=930481&r2=930482&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java Sat Apr  3 06:19:05
2010
@@ -817,9 +817,8 @@ public class LogUI extends JFrame implem
         	  int lineNumber = Integer.parseInt(inputLine);
               List eventList = getCurrentLogPanel().getEvents();
 
-              if (lineNumber > 0 && lineNumber <= eventList.size()) {
-                  getCurrentLogPanel().setSelectedEvent(lineNumber);
-              } else {
+              int row = getCurrentLogPanel().setSelectedEvent(lineNumber);
+              if (row == -1) {
                   JOptionPane.showMessageDialog(LogUI.this, "You have entered an invalid
line number", "Error", 0);
               }
           } catch (NumberFormatException nfe) {

Modified: logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/help/release-notes.html
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/help/release-notes.html?rev=930482&r1=930481&r2=930482&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/help/release-notes.html
(original)
+++ logging/chainsaw/trunk/src/main/resources/org/apache/log4j/chainsaw/help/release-notes.html
Sat Apr  3 06:19:05 2010
@@ -10,13 +10,19 @@
 <b>NOTE:</b> The mechanism and format used to persist settings in Chainsaw is
subject to change.  If you are experiencing problems displaying events in Chainsaw, please
delete everything in the $user.dir/.chainsaw directory and restart Chainsaw.
 <br>
 <h1>1.99.99</h1>
+<h2>2 Apr 2010</h2>
+<ul>
+<li>
+If the file-save as menu is provided a file ending in .zip, a zip file will be created containing
an xml file of the event contents.  By default, file-save as 
+just creates a text file containing the xml events.
+</li>
+</ul>
 <h2>1 Apr 2010</h2>
 <ul>
 <li>
 Updated thumbnail bar to display all events with a defined color (will include the default
color rules for marker, warning, error & fatal events).
 Added search matches to thumbnail bar (will display black in the left half of the row if
the row matches the search expression.
 Added ctrl-n to go to next colorized event, ctrl-p to go to previous colorized event.
-
 </li>
 </ul>
 <h2>27 Mar 2010</h2>



Mime
View raw message