You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ps...@apache.org on 2004/04/20 02:39:41 UTC

cvs commit: logging-log4j/src/java/org/apache/log4j/chainsaw/prefs default.properties

psmith      2004/04/19 17:39:40

  Modified:    src/java/org/apache/log4j/chainsaw LogUI.java
                        ApplicationPreferenceModelPanel.java
                        ApplicationPreferenceModel.java
               src/java/org/apache/log4j/chainsaw/prefs default.properties
  Log:
  This change adds a new Global property which defines a complete URL to a log4j.xml file
  that will be used at startup by Chainsaw as a way of initialising any Receivers
  the user usually deals with.  Saves having to bother with that NoReceiver warning dialog for users
  who are using Chainsaw frequently.
  
  This is somewhat of a duplicate effort to what the 'log4j.configuration' option would do
  but exposes the functionality via the GUI.
  
  The ApplicationPreferenceModelPanel is getting a bit messy now.  Might need to rethink
  how this is structured to make it easier to add changable properties to the GUI.
  
  Right now if you type a dud URL into the text field it is not 'accepted', but there is no visual
  clue that it has been rejected.  In fact, while the underlying preference model does not accept
  the change, the GUI seems to keep the value, which will be confusing!  :(
  
  I hope to add some decoration to indicate when the value entered has been accepted and
  to properly discard any old values correctly on Cancel.
  
  Revision  Changes    Path
  1.84      +19 -0     logging-log4j/src/java/org/apache/log4j/chainsaw/LogUI.java
  
  Index: LogUI.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/LogUI.java,v
  retrieving revision 1.83
  retrieving revision 1.84
  diff -u -r1.83 -r1.84
  --- LogUI.java	5 Apr 2004 07:22:12 -0000	1.83
  +++ LogUI.java	20 Apr 2004 00:39:40 -0000	1.84
  @@ -32,6 +32,7 @@
   import org.apache.log4j.chainsaw.prefs.SettingsListener;
   import org.apache.log4j.chainsaw.prefs.SettingsManager;
   import org.apache.log4j.chainsaw.receivers.ReceiversPanel;
  +import org.apache.log4j.helpers.LogLog;
   import org.apache.log4j.helpers.OptionConverter;
   import org.apache.log4j.net.SocketNodeEventListener;
   import org.apache.log4j.plugins.Plugin;
  @@ -42,6 +43,7 @@
   import org.apache.log4j.rule.ExpressionRule;
   import org.apache.log4j.rule.Rule;
   import org.apache.log4j.spi.LoggingEvent;
  +import org.apache.log4j.xml.DOMConfigurator;
   
   import java.awt.BorderLayout;
   import java.awt.Component;
  @@ -69,6 +71,7 @@
   
   import java.lang.reflect.Method;
   
  +import java.net.MalformedURLException;
   import java.net.URL;
   
   import java.util.ArrayList;
  @@ -107,6 +110,7 @@
   import javax.swing.event.EventListenerList;
   import javax.swing.event.HyperlinkEvent;
   import javax.swing.event.HyperlinkListener;
  +import javax.xml.parsers.FactoryConfigurationError;
   
   
   /**
  @@ -262,6 +266,21 @@
   
       logUI.handler = new ChainsawAppenderHandler();
       logUI.handler.addEventBatchListener(logUI.new NewTabEventBatchReceiver());
  +    
  +    
  +    String config = model.getConfigurationURL();
  +    if(config!=null) {
  +        config = config.trim();
  +        LogLog.info("Using '" + config + "' for auto-configuration");
  +        try {
  +            DOMConfigurator.configure(new URL(config));
  +        } catch (Exception e) {
  +            LogLog.error("Failed to use the auto-configuration file", e);
  +        }   
  +    }else {
  +        LogLog.info("No auto-configuration file found within the ApplicationPreferenceModel");
  +    }
  +    
       LogManager.getRootLogger().addAppender(logUI.handler);
       logUI.activateViewer();
   
  
  
  
  1.13      +37 -6     logging-log4j/src/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java
  
  Index: ApplicationPreferenceModelPanel.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ApplicationPreferenceModelPanel.java	27 Feb 2004 16:47:29 -0000	1.12
  +++ ApplicationPreferenceModelPanel.java	20 Apr 2004 00:39:40 -0000	1.13
  @@ -16,15 +16,12 @@
   
   package org.apache.log4j.chainsaw;
   
  -import org.apache.log4j.helpers.LogLog;
  -
   import java.awt.FlowLayout;
   import java.awt.event.ActionEvent;
   import java.awt.event.ActionListener;
  -
   import java.beans.PropertyChangeEvent;
   import java.beans.PropertyChangeListener;
  -
  +import java.net.URL;
   import java.util.Dictionary;
   import java.util.Enumeration;
   import java.util.Hashtable;
  @@ -33,7 +30,9 @@
   import javax.swing.Box;
   import javax.swing.BoxLayout;
   import javax.swing.ButtonGroup;
  +import javax.swing.InputVerifier;
   import javax.swing.JCheckBox;
  +import javax.swing.JComponent;
   import javax.swing.JFrame;
   import javax.swing.JLabel;
   import javax.swing.JPanel;
  @@ -48,6 +47,8 @@
   import javax.swing.tree.DefaultTreeModel;
   import javax.swing.tree.TreeModel;
   
  +import org.apache.log4j.helpers.LogLog;
  +
   
   /**
    * A panel used by the user to modify any application-wide preferences.
  @@ -59,8 +60,9 @@
     private ApplicationPreferenceModel committedPreferenceModel;
     private ApplicationPreferenceModel uncommittedPreferenceModel =
       new ApplicationPreferenceModel();
  -  JTextField identifierExpression;
  -  JTextField toolTipDisplayMillis;    
  +  private JTextField identifierExpression;
  +  private JTextField toolTipDisplayMillis;    
  +  private final JTextField configurationURL = new JTextField(25);
   
     ApplicationPreferenceModelPanel(ApplicationPreferenceModel model) {
       this.committedPreferenceModel = model;
  @@ -68,6 +70,7 @@
       getOkButton().addActionListener(
         new ActionListener() {
           public void actionPerformed(ActionEvent e) {
  +          uncommittedPreferenceModel.setConfigurationURL(configurationURL.getText());
             uncommittedPreferenceModel.setIdentifierExpression(
               identifierExpression.getText());
               try {
  @@ -84,6 +87,7 @@
       getCancelButton().addActionListener(
         new ActionListener() {
           public void actionPerformed(ActionEvent e) {
  +          uncommittedPreferenceModel.apply(committedPreferenceModel);
             hidePanel();
           }
         });
  @@ -406,7 +410,28 @@
         p4.add(toolTipDisplayMillis);
         add(p4);
   
  +      JPanel p5 = new JPanel(new FlowLayout(FlowLayout.LEFT));
  +
  +      p5.add(new JLabel("Automatic Configuration"));
  +      p5.add(Box.createHorizontalStrut(5));
  +      p5.add(configurationURL);
  +      add(p5);
  +
  +
         add(Box.createVerticalGlue());
  +      
  +      configurationURL.setToolTipText("A complete and valid URL identifying the location of a valid log4.xml file to auto-configure Receivers and other Plugins");
  +      configurationURL.setInputVerifier(new InputVerifier() {
  +
  +        public boolean verify(JComponent input)
  +        {
  +            try {
  +                new URL(configurationURL.getText());
  +            } catch (Exception e) {
  +                return false;
  +            }
  +            return true;
  +        }});
       }
   
       private void initSliderComponent() {
  @@ -519,6 +544,12 @@
             }
           });
   
  +      uncommittedPreferenceModel.addPropertyChangeListener("configurationURL", new PropertyChangeListener() {
  +
  +          public void propertyChange(PropertyChangeEvent evt) {
  +            String value = evt.getNewValue().toString();
  +            configurationURL.setText(value);
  +          }});
         confirmExit.addActionListener(
           new ActionListener() {
             public void actionPerformed(ActionEvent e) {
  
  
  
  1.17      +25 -0     logging-log4j/src/java/org/apache/log4j/chainsaw/ApplicationPreferenceModel.java
  
  Index: ApplicationPreferenceModel.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/ApplicationPreferenceModel.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- ApplicationPreferenceModel.java	28 Mar 2004 10:04:30 -0000	1.16
  +++ ApplicationPreferenceModel.java	20 Apr 2004 00:39:40 -0000	1.17
  @@ -49,6 +49,11 @@
       private final PropertyChangeSupport propertySupport =
           new PropertyChangeSupport(this);
       private int tabPlacement;
  +    
  +    /**
  +     * If not 'empty', this property will be used as the URL to load log4j configuration at startup
  +     */
  +    private String configurationURL="";
   
       /**
        * @param listener
  @@ -163,6 +168,7 @@
          setConfirmExit(event.asBoolean("confirmExit"));
          setShowSplash(event.asBoolean("showSplash"));
          setToolTipDisplayMillis(event.asInt("toolTipDisplayMillis"));
  +       setConfigurationURL(event.getSetting("configurationURL"));
       }
   
       /* (non-Javadoc)
  @@ -180,6 +186,7 @@
           event.saveSetting("confirmExit",isConfirmExit());
           event.saveSetting("showSplash", isShowSplash());
           event.saveSetting("toolTipDisplayMillis", getToolTipDisplayMillis());
  +        event.saveSetting("configurationURL", getConfigurationURL());
       }
   
       /**
  @@ -199,7 +206,9 @@
         setConfirmExit(model.isConfirmExit());
         setShowSplash(model.isShowSplash());
         setToolTipDisplayMillis(model.getToolTipDisplayMillis());
  +      setConfigurationURL(model.getConfigurationURL());
       }
  +    
       /**
        * @return Returns the responsiveness.
        */
  @@ -330,5 +339,21 @@
         boolean oldValue = this.showSplash;
         this.showSplash = showSplash;
         firePropertyChange("showSplash", oldValue,this.showSplash);
  +    }
  +    /**
  +     * @return Returns the configurationURL.
  +     */
  +    public final String getConfigurationURL()
  +    {
  +        return this.configurationURL;
  +    }
  +    /**
  +     * @param configurationURL The configurationURL to set.
  +     */
  +    public final void setConfigurationURL(String configurationURL)
  +    {
  +        Object oldValue = this.configurationURL;
  +        this.configurationURL = configurationURL;
  +        firePropertyChange("configurationURL", oldValue, this.configurationURL);
       }
   }
  
  
  
  1.15      +1 -0      logging-log4j/src/java/org/apache/log4j/chainsaw/prefs/default.properties
  
  Index: default.properties
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/prefs/default.properties,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- default.properties	28 Mar 2004 10:04:31 -0000	1.14
  +++ default.properties	20 Apr 2004 00:39:40 -0000	1.15
  @@ -24,6 +24,7 @@
   lookAndFeelClassName=
   confirmExit=true
   toolTipDisplayMillis=4000
  +configurationURL=
   
   # These are the default LogPanel settings
   dateFormatPattern=ISO8601
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org