User: ejort
Date: 01/12/23 19:45:10
Modified: src/main/org/jboss/logging LogAnalysis.java
LogAnalysisMBean.java
Log:
Highlight incorrect loggins in red.
Also allow a filter so only incorrect are shown.
Revision Changes Path
1.2 +220 -190 jboss/src/main/org/jboss/logging/LogAnalysis.java
Index: LogAnalysis.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/logging/LogAnalysis.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LogAnalysis.java 2001/12/23 18:51:34 1.1
+++ LogAnalysis.java 2001/12/24 03:45:10 1.2
@@ -1,33 +1,33 @@
-/*
-* 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 -----------------------------------------------------
-
+/*
+* 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.2 $
+ *
+ */
+public class LogAnalysis
+ extends ServiceMBeanSupport
+ implements LogAnalysisMBean
+{
+ // Constants -----------------------------------------------------
+
// Attributes ----------------------------------------------------
private HashMap analysis;
@@ -45,172 +45,202 @@
}
// 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();
- }
-
+
+ // LogAnalysisMBean implementation -------------------------------
+
+ public synchronized String analyse(boolean showAll)
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ 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();
+ Category category = (Category) e.getKey();
+ Analysis anal = (Analysis) e.getValue();
+
+ // Skip correct loggings unless showing everything
+ if (!showAll && getColor(category, TracePriority.TRACE,
anal.debug).equals("black")
+ && getColor(category, Priority.DEBUG, anal.debug).equals("black")
+ && getColor(category, Priority.INFO, anal.info).equals("black")
+ && getColor(category, Priority.WARN, anal.warn).equals("black")
+ && getColor(category, Priority.ERROR, anal.error).equals("black")
+ && getColor(category, Priority.FATAL, anal.fatal).equals("black"))
+ continue;
+
+ buffer.append("<tr>");
+ buffer.append("<td>");
+ buffer.append(category.getName());
+ buffer.append("</td>");
+
+ 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'><font color='");
+ buffer.append(getColor(category, TracePriority.TRACE, anal.trace));
+ buffer.append("'>");
+ buffer.append(anal.trace);
+ buffer.append("</font></td>");
+
+ buffer.append("<td align='center'><font color='");
+ buffer.append(getColor(category, Priority.DEBUG, anal.debug));
+ buffer.append("'>");
+ buffer.append(anal.debug);
+ buffer.append("</font></td>");
+
+ buffer.append("<td align='center'><font color='");
+ buffer.append(getColor(category, Priority.INFO, anal.info));
+ buffer.append("'>");
+ buffer.append(anal.info);
+ buffer.append("</font></td>");
+
+ buffer.append("<td align='center'><font color='");
+ buffer.append(getColor(category, Priority.WARN, anal.warn));
+ buffer.append("'>");
+ buffer.append(anal.warn);
+ buffer.append("</font></td>");
+
+ buffer.append("<td align='center'><font color='");
+ buffer.append(getColor(category, Priority.ERROR, anal.error));
+ buffer.append("'>");
+ buffer.append(anal.error);
+ buffer.append("</font></td>");
+
+ buffer.append("<td align='center'><font color='");
+ buffer.append(getColor(category, Priority.FATAL, anal.fatal));
+ buffer.append("'>");
+ buffer.append(anal.fatal);
+ buffer.append("</font></td>");
+
+ buffer.append("<td align='center'><font color='black'>");
+ buffer.append(anal.other);
+ buffer.append("</font></td>");
+
+ buffer.append("</tr>");
+ }
+ buffer.append("</table>");
+ }
+ 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;
- }
-}
+ 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 -------------------------------------------------------
+
+ /**
+ * Gets the color to display.
+ *
+ * @param Category the logging category
+ * @param Priority the logging priority
+ * @param count the number of logs
+ * @return red for incorrect logs, black otherwise
+ */
+ private String getColor(Category category, Priority priority, long count)
+ {
+ if (count == 0)
+ return "black";
+ if (!category.isEnabledFor(priority))
+ return "red";
+ if (priority.isGreaterOrEqual(category.getChainedPriority()))
+ return "black";
+ return "red";
+ }
+
+ // 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.2 +36 -33 jboss/src/main/org/jboss/logging/LogAnalysisMBean.java
Index: LogAnalysisMBean.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/logging/LogAnalysisMBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LogAnalysisMBean.java 2001/12/23 18:51:34 1.1
+++ LogAnalysisMBean.java 2001/12/24 03:45:10 1.2
@@ -1,33 +1,36 @@
-/*
-* 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, 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.2 $
+ *
+ */
+public interface LogAnalysisMBean
+ extends ServiceMBean
+{
+ // Constants -----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ /**
+ * Retrieve the analysis.
+ *
+ * @param showAll pass true for all logging calls, false to only show
+ * categories with incorrect loggings.
+ */
+ public String analyse(boolean showAll);
+}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development