logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject cvs commit: jakarta-log4j/src/java/org/apache/log4j/chainsaw/help Tutorial.java
Date Fri, 19 Sep 2003 07:06:40 GMT
psmith      2003/09/19 00:06:40

  Modified:    src/java/org/apache/log4j/chainsaw
                        ChainsawToolBarAndMenus.java
                        ReceiverTreeCellRenderer.java Generator.java
  Added:       src/java/org/apache/log4j/chainsaw/help Tutorial.java
  Log:
  Started adding the Tutorial code into Chainsaw.
  
  Now from the Help menu you can start the Tutorial.  Currently
  this installs a Generator fake receiver plugin into the Registry
  which streams random/benign events, allowing the user
  to see Chainsaw in actions.
  
  Still WIP.  Want to hook this up into the help system, add a few
  more generators etc.
  
  Revision  Changes    Path
  1.14      +13 -1     jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java
  
  Index: ChainsawToolBarAndMenus.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawToolBarAndMenus.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ChainsawToolBarAndMenus.java	13 Sep 2003 05:56:13 -0000	1.13
  +++ ChainsawToolBarAndMenus.java	19 Sep 2003 07:06:40 -0000	1.14
  @@ -55,6 +55,7 @@
    */
   package org.apache.log4j.chainsaw;
   
  +import org.apache.log4j.chainsaw.help.*;
   import org.apache.log4j.chainsaw.icons.ChainsawIcons;
   import org.apache.log4j.chainsaw.prefs.LoadSettingsEvent;
   import org.apache.log4j.chainsaw.prefs.SaveSettingsEvent;
  @@ -91,6 +92,7 @@
   import javax.swing.JMenu;
   import javax.swing.JMenuBar;
   import javax.swing.JMenuItem;
  +import javax.swing.JOptionPane;
   import javax.swing.JPanel;
   import javax.swing.JRadioButtonMenuItem;
   import javax.swing.JSlider;
  @@ -667,8 +669,18 @@
           }
         });
   
  -    helpMenu.add(about);
  +    
  +    Action startTutorial = new AbstractAction("Start tutorial...", new ImageIcon(ChainsawIcons.HELP)){
   
  +		public void actionPerformed(ActionEvent e) {
  +				new Thread(new Tutorial()).start();	
  +		}};
  +		
  +	startTutorial.putValue(Action.SHORT_DESCRIPTION, "Starts some pretend Receivers that generate
random events for use during the Tutorial");
  +	helpMenu.add(startTutorial);
  +	helpMenu.addSeparator();
  +    helpMenu.add(about);
  +    
       menuBar.add(fileMenu);
       menuBar.add(viewMenu);
       menuBar.add(activeTabMenu);
  
  
  
  1.4       +6 -1      jakarta-log4j/src/java/org/apache/log4j/chainsaw/ReceiverTreeCellRenderer.java
  
  Index: ReceiverTreeCellRenderer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/ReceiverTreeCellRenderer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ReceiverTreeCellRenderer.java	5 Sep 2003 06:11:11 -0000	1.3
  +++ ReceiverTreeCellRenderer.java	19 Sep 2003 07:06:40 -0000	1.4
  @@ -141,7 +141,12 @@
       } else if (o instanceof String) {
         setText(o.toString());
         setIcon(null);
  -    } else {
  +    }else if(o instanceof Generator){
  +    	Generator generator = (Generator) o;
  +    	setText(generator.getName());
  +    	setIcon(ChainsawIcons.ICON_HELP);
  +    } 
  +    else {
         setText("(Unknown Type) :: " + o);
       }
   
  
  
  
  1.2       +101 -41   jakarta-log4j/src/java/org/apache/log4j/chainsaw/Generator.java
  
  Index: Generator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/Generator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Generator.java	25 Jun 2003 04:05:22 -0000	1.1
  +++ Generator.java	19 Sep 2003 07:06:40 -0000	1.2
  @@ -49,9 +49,12 @@
   
   package org.apache.log4j.chainsaw;
   
  +import org.apache.log4j.Level;
   import org.apache.log4j.Logger;
   import org.apache.log4j.MDC;
   import org.apache.log4j.NDC;
  +import org.apache.log4j.plugins.Receiver;
  +import org.apache.log4j.spi.LoggingEvent;
   
   
   /**
  @@ -61,23 +64,31 @@
    * @author Scott Deboy <sdeboy@apache.org>
    *
    */
  -public class Generator extends Thread {
  -  private static final Logger logger1 = Logger.getLogger("first logger");
  -  private static final Logger logger2 = Logger.getLogger("some other logger");
  -  private static final Logger logger3 = Logger.getLogger("another logger");
  +public class Generator extends Receiver implements Runnable {
  +  private static final Logger logger1 =
  +    Logger.getLogger("com.mycompany.mycomponentA");
  +  private static final Logger logger2 =
  +    Logger.getLogger("com.mycompany.mycomponentB");
  +  private static final Logger logger3 =
  +    Logger.getLogger("com.someothercompany.corecomponent");
     private final String baseString_;
  +  private Thread thread;
  +  private boolean shutdown;
   
  -  public Generator(String baseString) {
  -    baseString_ = baseString;
  +  public Generator(String name) {
  +    setName(name);
  +    baseString_ = name;
     }
   
  -  public static void main(String[] args) {
  -    Thread t1 = new Generator("first");
  -    Thread t2 = new Generator("second");
  -    Thread t3 = new Generator("third");
  -    t1.start();
  -    t2.start();
  -    t3.start();
  +  private LoggingEvent createEvent(
  +    Level level, Logger logger, String msg, Throwable t) {
  +    LoggingEvent e =
  +      new LoggingEvent(
  +        logger.getClass().getName(), logger, System.currentTimeMillis(), level,
  +        msg, t);
  +    e.setProperty(ChainsawConstants.LOG4J_APP_KEY, getName());
  +
  +    return e;
     }
   
     public synchronized void run() {
  @@ -86,38 +97,87 @@
   
       int i = 0;
   
  -    while (i < 5000) {
  -      logger1.debug(
  -        "debugmsg " + i++
  -        + " g dg sdfa sadf sdf safd fsda asfd sdfa sdaf asfd asdf fasd fasd adfs fasd adfs
fads afds afds afsd afsd afsd afsd afsd fasd asfd asfd afsd fasd afsd",
  -        new Exception("someexception-" + baseString_));
  -      logger1.info(
  -        "infomsg " + i++, new Exception("someexception-" + baseString_));
  -      logger1.warn(
  -        "warnmsg " + i++, new Exception("someexception-" + baseString_));
  -      logger1.error(
  -        "errormsg " + i++, new Exception("someexception-" + baseString_));
  -      logger2.debug(
  -        "debugmsg " + i++, new Exception("someexception-" + baseString_));
  -      logger2.info(
  -        "infomsg " + i++, new Exception("someexception-" + baseString_));
  -      logger2.warn(
  -        "warnmsg " + i++, new Exception("someexception-" + baseString_));
  -      logger2.error(
  -        "errormsg " + i++, new Exception("someexception-" + baseString_));
  -      logger3.debug(
  -        "debugmsg " + i++, new Exception("someexception-" + baseString_));
  -      logger3.info(
  -        "infomsg " + i++, new Exception("someexception-" + baseString_));
  -      logger3.warn(
  -        "warnmsg " + i++, new Exception("someexception-" + baseString_));
  -      logger3.error(
  -        "errormsg " + i++, new Exception("someexception-" + baseString_));
  -
  +    while (!shutdown) {
  +      doPost(
  +        createEvent(
  +          Level.DEBUG, logger1,
  +          "debugmsg " + i++
  +          + " g dg sdfa sadf sdf safd fsda asfd sdfa sdaf asfd asdf fasd fasd adfs fasd
adfs fads afds afds afsd afsd afsd afsd afsd fasd asfd asfd afsd fasd afsd",
  +          new Exception("someexception-" + baseString_)));
  +
  +      //      if (isAsSevereAsThreshold(Level.INFO)) {
  +      //        logger1.info(
  +      //          "infomsg " + i++, new Exception("someexception-" + baseString_));
  +      //      }
  +      //
  +      //      if (isAsSevereAsThreshold(Level.WARN)) {
  +      //        logger1.warn(
  +      //          "warnmsg " + i++, new Exception("someexception-" + baseString_));
  +      //      }
  +      //
  +      //      if (isAsSevereAsThreshold(Level.ERROR)) {
  +      //        logger1.error(
  +      //          "errormsg " + i++, new Exception("someexception-" + baseString_));
  +      //      }
  +      //
  +      //      if (isAsSevereAsThreshold(Level.DEBUG)) {
  +      //        logger2.debug(
  +      //          "debugmsg " + i++, new Exception("someexception-" + baseString_));
  +      //      }
  +      //
  +      //      if (isAsSevereAsThreshold(Level.INFO)) {
  +      //        logger2.info(
  +      //          "infomsg " + i++, new Exception("someexception-" + baseString_));
  +      //      }
  +      //
  +      //      if (isAsSevereAsThreshold(Level.WARN)) {
  +      //        logger2.warn(
  +      //          "warnmsg " + i++, new Exception("someexception-" + baseString_));
  +      //      }
  +      //
  +      //      if (isAsSevereAsThreshold(Level.ERROR)) {
  +      //        logger2.error(
  +      //          "errormsg " + i++, new Exception("someexception-" + baseString_));
  +      //      }
  +      //
  +      //      if (isAsSevereAsThreshold(Level.DEBUG)) {
  +      //        logger3.debug(
  +      //          "debugmsg " + i++, new Exception("someexception-" + baseString_));
  +      //      }
  +      //
  +      //      if (isAsSevereAsThreshold(Level.INFO)) {
  +      //        logger3.info(
  +      //          "infomsg " + i++, new Exception("someexception-" + baseString_));
  +      //      }
  +      //
  +      //      if (isAsSevereAsThreshold(Level.WARN)) {
  +      //        logger3.warn(
  +      //          "warnmsg " + i++, new Exception("someexception-" + baseString_));
  +      //      }
  +      //
  +      //      if (isAsSevereAsThreshold(Level.ERROR)) {
  +      //        logger3.error(
  +      //          "errormsg " + i++, new Exception("someexception-" + baseString_));
  +      //      }
         try {
           Thread.sleep(1000);
         } catch (InterruptedException ie) {
         }
       }
  +  }
  +
  +  /* (non-Javadoc)
  +   * @see org.apache.log4j.plugins.Plugin#shutdown()
  +   */
  +  public void shutdown() {
  +    shutdown = true;
  +  }
  +
  +  /* (non-Javadoc)
  +   * @see org.apache.log4j.spi.OptionHandler#activateOptions()
  +   */
  +  public void activateOptions() {
  +    thread = new Thread(this);
  +    thread.start();
     }
   }
  
  
  
  1.1                  jakarta-log4j/src/java/org/apache/log4j/chainsaw/help/Tutorial.java
  
  Index: Tutorial.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package org.apache.log4j.chainsaw.help;
  
  import org.apache.log4j.chainsaw.Generator;
  import org.apache.log4j.plugins.Plugin;
  import org.apache.log4j.plugins.PluginRegistry;
  
  import javax.swing.JOptionPane;
  
  
  /**
   * A runnable element that installs into the Log4j environment some fake Receivers
   * which generates events for use as a tutorial.
   *
   * @author Paul Smith
   */
  public class Tutorial implements Runnable {
    /* (non-Javadoc)
     * @see java.lang.Runnable#run()
     */
    public void run() {
      if (
        JOptionPane.showConfirmDialog(
            null,
            "This will start some pretend receivers for us in the Tutorial.  Is that ok?",
            "Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
        Plugin p = new Generator("Generator 1");
        PluginRegistry.startPlugin(p);
      }
    }
  }
  
  
  

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


Mime
View raw message