logging-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sde...@apache.org
Subject svn commit: r668059 - in /logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw: LogPanel.java LogPanelPreferenceModel.java LogPanelPreferencePanel.java TableColorizingRenderer.java
Date Mon, 16 Jun 2008 06:28:42 GMT
Author: sdeboy
Date: Sun Jun 15 23:28:41 2008
New Revision: 668059

URL: http://svn.apache.org/viewvc?rev=668059&view=rev
Log:
New log panel preference: time zone of events on tab
Allows a user to specify (via the timezone abbreviation) the time zone of events on the tab,
providing the ability to view logs in local time.

For example, if events are from a log file which is in GMT, and you're in PST, set the time
zone preference to GMT and the timestamp field for events on that tab will be rendered +7
hours ahead of the actual event timestamp values.

Modified:
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanelPreferenceModel.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanelPreferencePanel.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java

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=668059&r1=668058&r2=668059&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 Sun Jun 15
23:28:41 2008
@@ -112,15 +112,13 @@
 import javax.swing.table.TableColumnModel;
 import javax.swing.text.Document;
 
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.io.xml.DomDriver;
-
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PatternLayout;
 import org.apache.log4j.chainsaw.color.ColorPanel;
 import org.apache.log4j.chainsaw.color.RuleColorizer;
 import org.apache.log4j.chainsaw.filter.FilterModel;
+import org.apache.log4j.chainsaw.helper.SwingHelper;
 import org.apache.log4j.chainsaw.icons.ChainsawIcons;
 import org.apache.log4j.chainsaw.icons.LineIconFactory;
 import org.apache.log4j.chainsaw.layout.DefaultLayoutFactory;
@@ -132,13 +130,15 @@
 import org.apache.log4j.chainsaw.prefs.SaveSettingsEvent;
 import org.apache.log4j.chainsaw.prefs.SettingsManager;
 import org.apache.log4j.chainsaw.xstream.TableColumnConverter;
-import org.apache.log4j.chainsaw.helper.SwingHelper;
 import org.apache.log4j.helpers.Constants;
 import org.apache.log4j.rule.ExpressionRule;
 import org.apache.log4j.rule.Rule;
 import org.apache.log4j.spi.LoggingEvent;
 import org.apache.log4j.spi.LoggingEventFieldResolver;
 
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.xml.DomDriver;
+
 
 /**
  * A LogPanel provides a view to a collection of LoggingEvents.<br>
@@ -475,6 +475,10 @@
           simpleTimeButton.setSelected(
             !model.isUseISO8601Format() && !model.isCustomDateFormat());
 
+          if (model.getTimeZone() != null) {
+            renderer.setTimeZone(model.getTimeZone());
+          }
+          
           if (model.isUseISO8601Format()) {
             renderer.setDateFormatter(new SimpleDateFormat(Constants.ISO8601_PATTERN));
           } else {
@@ -493,8 +497,7 @@
 
     preferenceModel.addPropertyChangeListener(
       "dateFormatPattern", datePrefsChangeListener);
-    preferenceModel.addPropertyChangeListener(
-      "dateFormatPattern", datePrefsChangeListener);
+    preferenceModel.addPropertyChangeListener("dateFormatTimeZone", datePrefsChangeListener);
 
     preferenceModel.addPropertyChangeListener(
       "loggerPrecision",

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanelPreferenceModel.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanelPreferenceModel.java?rev=668059&r1=668058&r2=668059&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanelPreferenceModel.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanelPreferenceModel.java
Sun Jun 15 23:28:41 2008
@@ -77,6 +77,7 @@
   private String loggerPrecision = "";
 
   private Collection hiddenLoggers = new HashSet();
+  private String timeZone;
   
   /**
    * Returns an <b>unmodifiable</b> list of the columns.
@@ -215,6 +216,7 @@
     setLoggerPrecision(model.getLoggerPrecision());
     setDateFormatPattern(model.getDateFormatPattern());
     setLevelIcons(model.isLevelIcons());
+    setTimeZone(model.getTimeZone());
     setToolTips(model.isToolTips());
     setScrollToBottom(model.isScrollToBottom());
     setDetailPaneVisible(model.isDetailPaneVisible());
@@ -395,7 +397,17 @@
       propertySupport.firePropertyChange("hiddenLoggers", oldValue, this.hiddenLoggers);
   }
 
-public Collection getHiddenLoggers() {
+  public Collection getHiddenLoggers() {
     return hiddenLoggers;
-}
+  }
+
+  public String getTimeZone() {
+    return timeZone;
+  }
+  
+  public void setTimeZone(String timeZone) {
+      Object oldValue = this.timeZone;
+      this.timeZone = timeZone;
+      propertySupport.firePropertyChange("dateFormatTimeZone", oldValue, this.timeZone);
+  }
 }

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanelPreferencePanel.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanelPreferencePanel.java?rev=668059&r1=668058&r2=668059&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanelPreferencePanel.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogPanelPreferencePanel.java
Sun Jun 15 23:28:41 2008
@@ -18,7 +18,6 @@
 
 import java.awt.Component;
 import java.awt.Dimension;
-import java.awt.FlowLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.InputEvent;
@@ -41,6 +40,7 @@
 import javax.swing.JRadioButton;
 import javax.swing.JScrollPane;
 import javax.swing.JTextField;
+import javax.swing.SwingConstants;
 import javax.swing.table.TableColumn;
 import javax.swing.tree.DefaultMutableTreeNode;
 import javax.swing.tree.DefaultTreeModel;
@@ -223,11 +223,12 @@
     //~ Instance fields =======================================================
 
     private JTextField customFormatText = new JTextField("", 10);
-    private JTextField loggerPrecision = new JTextField(5);
+    private JTextField loggerPrecision = new JTextField(10);
     private JRadioButton rdCustom = new JRadioButton("Custom Format");
     private final JRadioButton rdISO =
       new JRadioButton(
         "<html><b>Fast</b> ISO 8601 format (yyyy-MM-dd HH:mm:ss)</html>");
+    private final JTextField timeZone = new JTextField(10);
     private final JRadioButton rdLevelIcons = new JRadioButton("Icons");
     private final JRadioButton rdLevelText = new JRadioButton("Text");
     private JRadioButton rdLast;
@@ -248,25 +249,18 @@
       setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
 
       JPanel dateFormatPanel = new JPanel();
+      dateFormatPanel.setLayout(new BoxLayout(dateFormatPanel, BoxLayout.Y_AXIS));
       dateFormatPanel.setBorder(
         BorderFactory.createTitledBorder(
           BorderFactory.createEtchedBorder(), "Timestamp"));
-      dateFormatPanel.setLayout(
-        new BoxLayout(dateFormatPanel, BoxLayout.Y_AXIS));
-      dateFormatPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
-
-      customFormatText.setPreferredSize(new Dimension(100, 20));
-      customFormatText.setMaximumSize(customFormatText.getPreferredSize());
-      customFormatText.setMinimumSize(customFormatText.getPreferredSize());
-      customFormatText.setEnabled(false);
-
-      rdCustom.setSelected(preferenceModel.isCustomDateFormat());
 
       ButtonGroup bgDateFormat = new ButtonGroup();
 
-      rdISO.setAlignmentX(0);
       rdISO.setSelected(preferenceModel.isUseISO8601Format());
 
+      rdISO.setHorizontalTextPosition(SwingConstants.RIGHT);
+      rdISO.setAlignmentX(Component.LEFT_ALIGNMENT);      
+
       bgDateFormat.add(rdISO);
       dateFormatPanel.add(rdISO);
 
@@ -276,9 +270,9 @@
       {
         final String format = (String) iter.next();
         final JRadioButton rdFormat = new JRadioButton(format);
-        rdFormat.setAlignmentX(0);
+        rdFormat.setHorizontalTextPosition(SwingConstants.RIGHT);
+        rdFormat.setAlignmentX(Component.LEFT_ALIGNMENT);      
 
-        bgDateFormat.add(rdFormat);
         rdFormat.addActionListener(new ActionListener()
           {
             public void actionPerformed(ActionEvent e)
@@ -302,8 +296,17 @@
           });
 
         dateFormatPanel.add(rdFormat);
+        bgDateFormat.add(rdFormat);
       }
 
+      customFormatText.setPreferredSize(new Dimension(100, 20));
+      customFormatText.setMaximumSize(customFormatText.getPreferredSize());
+      customFormatText.setMinimumSize(customFormatText.getPreferredSize());
+      customFormatText.setEnabled(false);
+
+      bgDateFormat.add(rdCustom);
+      rdCustom.setSelected(preferenceModel.isCustomDateFormat());
+
       // add a custom date format
       if (preferenceModel.isCustomDateFormat())
       {
@@ -311,19 +314,22 @@
         customFormatText.setEnabled(true);
       }
 
-      rdCustom.setAlignmentX(0);
-      bgDateFormat.add(rdCustom);
-
-      Box customBox = Box.createHorizontalBox();
-
-      //      Following does not work in JDK 1.3.1
-      //      customBox.setAlignmentX(0);
-      customBox.add(rdCustom);
-      customBox.add(customFormatText);
-      customBox.add(Box.createHorizontalGlue());
-      dateFormatPanel.add(customBox);
-
-      //      dateFormatPanel.add(Box.createVerticalGlue());
+      JPanel customPanel = new JPanel();
+      customPanel.setLayout(new BoxLayout(customPanel, BoxLayout.X_AXIS));
+      customPanel.add(rdCustom);
+      customPanel.add(customFormatText);
+      customPanel.setAlignmentX(Component.LEFT_ALIGNMENT);      
+
+      dateFormatPanel.add(customPanel);
+      dateFormatPanel.add(Box.createVerticalStrut(5));
+
+      JLabel dateFormatLabel = new JLabel("Time zone of events on tab (leave blank for local
time zone");
+      dateFormatPanel.add(dateFormatLabel);
+
+      timeZone.setMaximumSize(timeZone.getPreferredSize());
+      dateFormatPanel.add(Box.createVerticalStrut(5));
+      dateFormatPanel.add(timeZone);
+      
       add(dateFormatPanel);
 
       JPanel levelFormatPanel = new JPanel();
@@ -353,21 +359,18 @@
           BorderFactory.createEtchedBorder(), "Logger"));
       loggerFormatPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
 
+      loggerFormatPanel.add(Box.createVerticalStrut(3));
+
       final JLabel precisionLabel =
-        new JLabel("Number of package levels to hide)");
-      final JLabel precisionLabel2 =
-        new JLabel("leave blank to display full logger");
+        new JLabel("Number of package levels to hide (leave blank to display full logger)");
 
       loggerFormatPanel.add(precisionLabel);
-      loggerFormatPanel.add(precisionLabel2);
+      loggerFormatPanel.add(Box.createVerticalStrut(5));
 
-      JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
-
-      p.add(loggerPrecision);
-      loggerFormatPanel.add(p);
+      loggerPrecision.setMaximumSize(loggerPrecision.getPreferredSize());
+      loggerFormatPanel.add(loggerPrecision);
 
       add(loggerFormatPanel);
-
       add(Box.createVerticalGlue());
     }
 
@@ -386,6 +389,7 @@
     	}
     	
     	loggerPrecision.setText(preferenceModel.getLoggerPrecision());
+    	timeZone.setText(preferenceModel.getTimeZone());
     }
 
     /*
@@ -396,6 +400,7 @@
     		preferenceModel.setDateFormatPattern(customFormatText.getText());
     	}
     	preferenceModel.setLoggerPrecision(loggerPrecision.getText());
+    	preferenceModel.setTimeZone(timeZone.getText());
     }
 
     /**
@@ -468,6 +473,13 @@
             rdLast = rdISO;
           }
         });
+      preferenceModel.addPropertyChangeListener(
+          "dateFormatTimeZone", new PropertyChangeListener() {
+              public void propertyChange(PropertyChangeEvent evt) {
+                  timeZone.setText(preferenceModel.getTimeZone());
+              }
+          }
+      );
 
       ActionListener levelIconListener = new ActionListener()
         {

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java?rev=668059&r1=668058&r2=668059&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/TableColorizingRenderer.java
Sun Jun 15 23:28:41 2008
@@ -17,19 +17,13 @@
 
 package org.apache.log4j.chainsaw;
 
-import org.apache.log4j.chainsaw.color.Colorizer;
-import org.apache.log4j.chainsaw.icons.LevelIconFactory;
-import org.apache.log4j.helpers.Constants;
-import org.apache.log4j.spi.LoggingEvent;
-
 import java.awt.Color;
 import java.awt.Component;
-
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
-
 import java.util.Date;
 import java.util.Map;
+import java.util.TimeZone;
 
 import javax.swing.BorderFactory;
 import javax.swing.Icon;
@@ -38,6 +32,11 @@
 import javax.swing.SwingConstants;
 import javax.swing.table.DefaultTableCellRenderer;
 
+import org.apache.log4j.chainsaw.color.Colorizer;
+import org.apache.log4j.chainsaw.icons.LevelIconFactory;
+import org.apache.log4j.helpers.Constants;
+import org.apache.log4j.spi.LoggingEvent;
+
 
 /**
  * A specific TableCellRenderer that colourizes a particular cell based on
@@ -60,6 +59,7 @@
   private DateFormat dateFormatInUse = DATE_FORMATTER;
   private int loggerPrecision = 0;
   private boolean toolTipsVisible;
+  private String dateFormatTZ;
 
   /**
    * Creates a new TableColorizingRenderer object.
@@ -197,6 +197,11 @@
    */
   void setDateFormatter(DateFormat formatter) {
     this.dateFormatInUse = formatter;
+    if (dateFormatInUse != null && dateFormatTZ != null && !("".equals(dateFormatTZ)))
{
+      dateFormatInUse.setTimeZone(TimeZone.getTimeZone(dateFormatTZ));
+    } else {
+      dateFormatInUse.setTimeZone(TimeZone.getDefault());
+    }
   }
 
   /**
@@ -222,6 +227,7 @@
     if (!(o instanceof Date)) {
       return (o == null ? "" : o);
     }
+    
     return dateFormatInUse.format((Date) o);
   }
 
@@ -240,4 +246,14 @@
   public void setLevelUseIcons(boolean levelUseIcons) {
     this.levelUseIcons = levelUseIcons;
   }
+
+  public void setTimeZone(String dateFormatTZ) {
+    this.dateFormatTZ = dateFormatTZ;
+
+    if (dateFormatInUse != null && dateFormatTZ != null && !("".equals(dateFormatTZ)))
{
+      dateFormatInUse.setTimeZone(TimeZone.getTimeZone(dateFormatTZ));
+    } else {
+      dateFormatInUse.setTimeZone(TimeZone.getDefault());
+    }
+  }
 }



Mime
View raw message