User: ejort   
  Date: 01/12/23 10:51:34

  Modified:    src/main/org/jboss/logging Logger.java
  Added:       src/main/org/jboss/logging LogAnalysis.java
                        LogAnalysisMBean.java
  Log:
  Log Analysis Service for debugging logging calls.
  Will probably want removing before 3.0 goes stable.
  
  Revision  Changes    Path
  1.16      +46 -1     jboss/src/main/org/jboss/logging/Logger.java
  
  Index: Logger.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/logging/Logger.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Logger.java       2001/11/26 03:16:09     1.15
  +++ Logger.java       2001/12/23 18:51:34     1.16
  @@ -17,7 +17,7 @@
    * @see #trace(Object, Throwable)
   
    * @author [EMAIL PROTECTED]
  - * @version $Revision: 1.15 $
  + * @version $Revision: 1.16 $
    */
   public class Logger
   {
  @@ -26,6 +26,11 @@
      // Attributes ----------------------------------------------------
      private Category log;
   
  +   /**
  +    * The analysis handler
  +    */
  +   private static LogAnalysis analysis = null;
  +
      // Static --------------------------------------------------------
   
      /** Create a Logger instance given the category name.
  @@ -76,6 +81,8 @@
      */
      public void trace(Object message)
      {
  +      if (analysis != null)
  +        analysis.add(log, TracePriority.TRACE);
         log.log(TracePriority.TRACE, message);
      }
      /** Issue a log msg and throwable with a priority of TRACE.
  @@ -83,6 +90,8 @@
      */
      public void trace(Object message, Throwable t)
      {
  +      if (analysis != null)
  +        analysis.add(log, TracePriority.TRACE);
         log.log(TracePriority.TRACE, message, t);
      }
   
  @@ -103,6 +112,8 @@
      */
      public void debug(Object message)
      {
  +      if (analysis != null)
  +        analysis.add(log, Priority.DEBUG);
         log.log(Priority.DEBUG, message);
      }
      /** Issue a log msg and throwable with a priority of DEBUG.
  @@ -110,6 +121,8 @@
      */
      public void debug(Object message, Throwable t)
      {
  +      if (analysis != null)
  +        analysis.add(log, Priority.DEBUG);
         log.log(Priority.DEBUG, message, t);
      }
   
  @@ -130,6 +143,8 @@
      */
      public void info(Object message)
      {
  +      if (analysis != null)
  +        analysis.add(log, Priority.INFO);
         log.log(Priority.INFO, message);
      }
      /** Issue a log msg and throwable with a priority of INFO.
  @@ -137,6 +152,8 @@
      */
      public void info(Object message, Throwable t)
      {
  +      if (analysis != null)
  +        analysis.add(log, Priority.INFO);
         log.log(Priority.INFO, message, t);
      }
   
  @@ -145,6 +162,8 @@
      */
      public void warn(Object message)
      {
  +      if (analysis != null)
  +        analysis.add(log, Priority.WARN);
         log.log(Priority.WARN, message);
      }
      /** Issue a log msg and throwable with a priority of WARN.
  @@ -152,6 +171,8 @@
      */
      public void warn(Object message, Throwable t)
      {
  +      if (analysis != null)
  +        analysis.add(log, Priority.WARN);
         log.log(Priority.WARN, message, t);
      }
   
  @@ -160,6 +181,8 @@
      */
      public void error(Object message)
      {
  +      if (analysis != null)
  +        analysis.add(log, Priority.ERROR);
         log.log(Priority.ERROR, message);
      }
      /** Issue a log msg and throwable with a priority of ERROR.
  @@ -167,6 +190,8 @@
      */
      public void error(Object message, Throwable t)
      {
  +      if (analysis != null)
  +        analysis.add(log, Priority.ERROR);
         log.log(Priority.ERROR, message, t);
      }
   
  @@ -175,6 +200,8 @@
      */
      public void fatal(Object message)
      {
  +      if (analysis != null)
  +        analysis.add(log, Priority.FATAL);
         log.log(Priority.FATAL, message);
      }
      /** Issue a log msg and throwable with a priority of FATAL.
  @@ -182,6 +209,8 @@
      */
      public void fatal(Object message, Throwable t)
      {
  +      if (analysis != null)
  +        analysis.add(log, Priority.FATAL);
         log.log(Priority.FATAL, message, t);
      }
   
  @@ -190,6 +219,8 @@
      */
      public void log(Priority p, Object message)
      {
  +      if (analysis != null)
  +        analysis.add(log, p);
         log.log(p, message);
      }
      /** Issue a log msg with the given priority.
  @@ -197,6 +228,20 @@
      */
      public void log(Priority p, Object message, Throwable t)
      {
  +      if (analysis != null)
  +        analysis.add(log, p);
         log.log(p, message, t);
      }
  +
  +  // Package Private -----------------------------------------------
  +
  +  /**
  +   * Set the analysis handler.
  +   *
  +   * @param value the analysis handler.
  +   */
  +  static void setAnalysis(LogAnalysis value)
  +  {
  +    analysis = value;
  +  }
   }
  
  
  
  1.1                  jboss/src/main/org/jboss/logging/LogAnalysis.java
  
  Index: LogAnalysis.java
  ===================================================================
  /*
  * JBoss, the OpenSource EJB server
  *
  * Distributable under LGPL license.
  * See terms of license at gnu.org.
  */
  package org.jboss.logging;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.log4j.Category;
  import org.apache.log4j.Priority;
  
  import org.jboss.system.ServiceMBeanSupport;
  
  /**
   * The log analysis service.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Adrian Brock</a>
   * @version $Revision: 1.1 $
   *
   */
  public class LogAnalysis
    extends ServiceMBeanSupport
    implements LogAnalysisMBean
  {
    // Constants -----------------------------------------------------
  
    // Attributes ----------------------------------------------------
    
    private HashMap analysis;
  
    // Static --------------------------------------------------------
  
    // Constructors --------------------------------------------------
  
    /**
     * Default constructor.
     */
    public LogAnalysis()
    {
      analysis = new HashMap();
    }
  
    // Public --------------------------------------------------------
  
    // LogAnalysisMBean implementation -------------------------------
  
    public synchronized String analyse()
    {
      StringBuffer buffer = new StringBuffer();
  try
  {
  
      // Add the count
      buffer.append("<h1>Total Categories: ");
      buffer.append(analysis.size());
      buffer.append("</h1>");
  
      if (analysis.size() > 0)
      {
        buffer.append("<h2><center>Messages by category and priority</center></h2>");
  
        // Add the table header
        buffer.append("<table border='1' align='center' cellpadding='3'><tr>");
        buffer.append("<th>Category</th>");
        buffer.append("<th>Total</th>");
        buffer.append("<th>Trace</th>");
        buffer.append("<th>Debug</th>");
        buffer.append("<th>Info</th>");
        buffer.append("<th>Warn</th>");
        buffer.append("<th>Error</th>");
        buffer.append("<th>Fatal</th>");
        buffer.append("<th>Other</th>");
        buffer.append("</tr>");
  
        // Add each map entry as a table row
        Iterator i = analysis.entrySet().iterator();
        while(i.hasNext())
        {
          Map.Entry e = (Map.Entry) i.next();
          buffer.append("<tr>");
          buffer.append("<td>");
          buffer.append(((Category)e.getKey()).getName());
          buffer.append("</td>");
  
          Analysis anal = (Analysis) e.getValue();
          buffer.append("<td align='center'>");
          buffer.append(anal.trace + anal.debug + anal.info + anal.warn + anal.error + 
anal.fatal + anal.other);
          buffer.append("</td>");
  
          buffer.append("<td align='center'>");
          buffer.append(anal.trace);
          buffer.append("</td>");
  
          buffer.append("<td align='center'>");
          buffer.append(anal.debug);
          buffer.append("</td>");
  
          buffer.append("<td align='center'>");
          buffer.append(anal.info);
          buffer.append("</td>");
  
          buffer.append("<td align='center'>");
          buffer.append(anal.warn);
          buffer.append("</td>");
  
          buffer.append("<td align='center'>");
          buffer.append(anal.error);
          buffer.append("</td>");
  
          buffer.append("<td align='center'>");
          buffer.append(anal.fatal);
          buffer.append("</td>");
  
          buffer.append("<td align='center'>");
          buffer.append(anal.other);
          buffer.append("</td>");
  
          buffer.append("</tr>");
        }
        buffer.append("</table>");
      }
   }
  catch (Exception e)
  {
    buffer.append(e);
  }
      return buffer.toString();
    }
  
    // ServiceMBeanSupport overrides ---------------------------------
  
    public void startService()
      throws Exception
    {
      Logger.setAnalysis(this);
    }
  
    public void stopService()
    {
      Logger.setAnalysis(null);
      analysis.clear();
    }
  
    public String getName()
    {
      return "Log analysis";
    }
  
    // Package protected ---------------------------------------------
  
    /**
     * Add one to the count for this category and priority.
     *
     * @param log the logging category.
     * @param type the priority.
     */
    public synchronized void add(Category log, Priority type)
    {
       if (!analysis.containsKey(log))
         analysis.put(log, new Analysis());
       Analysis anal = (Analysis) analysis.get(log);
       if (type == TracePriority.TRACE)
         anal.trace++;
       else if (type == Priority.DEBUG)
         anal.debug++;
       else if (type == Priority.INFO)
         anal.info++;
       else if (type == Priority.WARN)
         anal.warn++;
       else if (type == Priority.ERROR)
         anal.error++;
       else if (type == Priority.FATAL)
         anal.fatal++;
       else 
         anal.other++;
    }
  
    // Protected -----------------------------------------------------
  
    // Private -------------------------------------------------------
  
    // Inner classes -------------------------------------------------
  
    /**
     * The analysis data for each log.
     */
    private class Analysis
    {
      // Attributes ----------------------------------------------------
  
      // The number of trace logs
      public long trace;
  
      // The number of debug logs
      public long debug;
  
      // The number of info logs
      public long info;
  
      // The number of warn logs
      public long warn;
  
      // The number of error logs
      public long error;
  
      // The number of fatal logs
      public long fatal;
  
      // The number of other logs
      public long other;
    }
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/logging/LogAnalysisMBean.java
  
  Index: LogAnalysisMBean.java
  ===================================================================
  /*
  * JBoss, the OpenSource EJB server
  *
  * Distributable under LGPL license.
  * See terms of license at gnu.org.
  */
  package org.jboss.logging;
  
  import javax.management.ObjectName;
  
  import org.jboss.system.ServiceMBean;
  
  /**
   * The log analysis service MBean interface. <p>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Adrian Brock</a>
   * @version $Revision: 1.1 $
   *
   */
  public interface LogAnalysisMBean
    extends ServiceMBean
  {
    // Constants -----------------------------------------------------
    
    // Static --------------------------------------------------------
    
    // Public --------------------------------------------------------
  
    /**
     * Retrieve the analysis.
     */
    public String analyse();
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to