You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by cu...@apache.org on 2001/02/21 01:47:16 UTC

cvs commit: xml-xalan/test/java/src/org/apache/qetest ConsoleLogger.java

curcuru     01/02/20 16:47:16

  Modified:    test/java/src/org/apache/qetest ConsoleLogger.java
  Log:
  Implement ConsoleLogger.loggingLevel, a separate logging level
  just for console output; still needs coordination with Reporter and Test
  
  Revision  Changes    Path
  1.5       +138 -17   xml-xalan/test/java/src/org/apache/qetest/ConsoleLogger.java
  
  Index: ConsoleLogger.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/ConsoleLogger.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConsoleLogger.java	2000/12/05 19:16:12	1.4
  +++ ConsoleLogger.java	2001/02/21 00:47:16	1.5
  @@ -70,8 +70,20 @@
   
   /**
    * Logger that prints human-readable output to System.out.
  + * As an experiment, the ConsoleLogger supports an independent
  + * loggingLevel that can be more restrictive than a loggingLevel 
  + * set in any enclosing Reporter.  
  + * Note this isn't quite as well architected as I would like, 
  + * but it does address what seems to be the 
  + * most common usage case: where you're running tests automatically, 
  + * and likely will be using some file-based output for results 
  + * analysis.  This allows you to set loggingLevel for your Reporter
  + * high, so that most/all output is sent to the file, but set this 
  + * ConsoleLogger's loggingLevel low, so only critical problems 
  + * are displayed on the screen (since most of the time users will 
  + * never be watching the console in this situation).
    * @author Shane_Curcuru@lotus.com
  - * @version $Id: ConsoleLogger.java,v 1.4 2000/12/05 19:16:12 curcuru Exp $
  + * @version $Id: ConsoleLogger.java,v 1.5 2001/02/21 00:47:16 curcuru Exp $
    */
   public class ConsoleLogger implements Logger
   {
  @@ -95,6 +107,19 @@
       /** Generic properties for this Logger; sort-of replaces instance variables. */
       protected Properties loggerProps = null;
   
  +    /** 
  +    * Special LoggingLevel for just this instance.  
  +    * May be set from "ConsoleLogger.loggingLevel" property;
  +    * defaults to 100 which should be larger than any other 
  +    * loggingLevels in use currently.
  +    * Note that different levels here will even restrict output 
  +    * from control messages like testCaseInit; see individual 
  +    * javadocs for what controls what.  This may affect the level 
  +    * of indenting you see as well; I traded off a little speed
  +    * (don't calc indent if not using that message) for prettiness.
  +    */
  +    protected int consoleLoggingLevel = 100;
  +    
       //-----------------------------------------------------
       //-------- Control and utility routines --------
       //-----------------------------------------------------
  @@ -132,7 +157,8 @@
   
           String pinfo[][] =
           {
  -            { OPT_INDENT, "boolean", "If reporter should indent sub-results" }
  +            { OPT_INDENT, "boolean", "If reporter should indent sub-results" },
  +            { "ConsoleLogger.loggingLevel", "String", "loggingLevel for just ConsoleLogger; only if more restrictive than other loggingLevels" }
           };
   
           return pinfo;
  @@ -165,10 +191,9 @@
        * Call once to initialize this Logger/Reporter from Properties.
        * @param Properties block to initialize from.
        * @param status, true if OK, false if an error occoured.
  -     *
  -     * NEEDSDOC @param p
        *
  -     * NEEDSDOC ($objectName$) @return
  +     * @param p Properties block to initialize from
  +     * @return true if OK; currently always returns true
        */
       public boolean initialize(Properties p)
       {
  @@ -187,6 +212,23 @@
                   indent = true;
           }
   
  +        // Grab our specific loggingLevel and set if needed
  +        String logLvl = loggerProps.getProperty("ConsoleLogger.loggingLevel");
  +        if (logLvl != null)
  +        {
  +            // Note: if present, we'll attempt to set it
  +            // It doesn't really make much sense to set it if 
  +            //  this value is larger than an enclosing Reporter's 
  +            //  loggingLevel, but it won't hurt either
  +            try
  +            {
  +                consoleLoggingLevel = Integer.parseInt(logLvl);
  +            }
  +            catch (NumberFormatException numEx)
  +            { /* no-op */
  +            }
  +        }
  +
           ready = true;
   
           return true;
  @@ -203,6 +245,7 @@
   
       /**
        * Is this Logger/Reporter still running OK?
  +     * //@todo rename method; too confusing with boolean checkErr(String)
        * @return false - ConsoleLoggers never have errors
        */
       public boolean checkError()
  @@ -248,43 +291,63 @@
   
       /**
        * Report that a testfile has started.
  +     * Output only when ConsoleLogger.loggingLevel >= ERRORMSG
  +     *
        * @param name file name or tag specifying the test.
        * @param comment comment about the test.
        */
       public void testFileInit(String name, String comment)
       {
  +        if (consoleLoggingLevel < ERRORMSG)
  +            return;
  +            
           outStream.println(sIndent + "TestFileInit " + name + ":" + comment);
           indent();
       }
   
       /**
        * Report that a testfile has finished, and report it's result.
  +     * Output only when ConsoleLogger.loggingLevel >= ERRORMSG
  +     *
        * @param msg message or name of test to log out
        * @param result result of testfile
        */
       public void testFileClose(String msg, String result)
       {
  +        if (consoleLoggingLevel < ERRORMSG)
  +            return;
  +            
           outdent();
           outStream.println(sIndent + "TestFileClose(" + result + ") " + msg);
       }
   
       /**
        * Report that a testcase has started.
  +     * Output only when ConsoleLogger.loggingLevel >= WARNINGMSG
  +     *
        * @param comment short description of this test case's objective.
        */
       public void testCaseInit(String comment)
       {
  +        if (consoleLoggingLevel < WARNINGMSG)
  +            return;
  +            
           outStream.println(sIndent + "TestCaseInit " + comment);
           indent();
       }
   
       /**
        * Report that a testcase has finished, and report it's result.
  +     * Output only when ConsoleLogger.loggingLevel >= WARNINGMSG
  +     *
        * @param msg message of name of test case to log out
        * @param result result of testfile
        */
       public void testCaseClose(String msg, String result)
       {
  +        if (consoleLoggingLevel < WARNINGMSG)
  +            return;
  +            
           outdent();
           outStream.println(sIndent + "TestCaseClose(" + result + ") " + msg);
       }
  @@ -295,40 +358,49 @@
   
       /**
        * Report a comment to result file with specified severity.
  -     * ConsoleLoggers ignore message severities.
  +     * Output only when ConsoleLogger.loggingLevel >= level
  +     *
        * @param level severity or class of message.
        * @param msg comment to log out.
        */
       public void logMsg(int level, String msg)
       {
  +        if (consoleLoggingLevel < level)
  +            return;
  +            
           outStream.println(sIndent + msg);
       }
   
       /**
        * Report an arbitrary String to result file with specified severity.
        * Log out the String provided exactly as-is.
  -     * @param severity or class of message.
  -     * @param arbitrary String to log out.
  +     * Output only when ConsoleLogger.loggingLevel >= level
        *
  -     * NEEDSDOC @param level
  -     * NEEDSDOC @param msg
  +     * @param level severity or class of message.
  +     * @param msg arbitrary String to log out.
        */
       public void logArbitrary(int level, String msg)
       {
  +        if (consoleLoggingLevel < level)
  +            return;
  +            
           outStream.println(msg);
       }
   
       /**
        * Logs out statistics to result file with specified severity.
  -     * @param severity of message.
  +     * Output only when ConsoleLogger.loggingLevel >= level
        *
  -     * NEEDSDOC @param level
  +     * @param level severity of message.
        * @param lVal statistic in long format.
        * @param dVal statistic in double format.
        * @param msg comment to log out.
        */
       public void logStatistic(int level, long lVal, double dVal, String msg)
       {
  +        if (consoleLoggingLevel < level)
  +            return;
  +            
           outStream.println(sIndent + msg + " l: " + lVal + " d: " + dVal);
       }
   
  @@ -341,6 +413,8 @@
        *    ...
        *    msg.toString()
        * </pre>
  +     * Output only when ConsoleLogger.loggingLevel >= level
  +     *
        * @param level severity of message.
        * @param element name of enclosing element
        * @param attrs hash of name=value attributes
  @@ -350,6 +424,9 @@
       public void logElement(int level, String element, Hashtable attrs,
                              Object msg)
       {
  +        if (consoleLoggingLevel < level)
  +            return;
  +            
           if ((element == null)
              || (attrs == null))
           {
  @@ -379,13 +456,17 @@
   
       /**
        * Logs out contents of a Hashtable with specified severity.
  +     * Output only when ConsoleLogger.loggingLevel >= level
  +     *
        * @param level severity or class of message.
        * @param hash Hashtable to log the contents of.
        * @param msg decription of the Hashtable.
        */
       public void logHashtable(int level, Hashtable hash, String msg)
       {
  -
  +        if (consoleLoggingLevel < level)
  +            return;
  +            
           indent();
           outStream.println(sIndent + "HASHTABLE: " + msg);
           indent();
  @@ -426,37 +507,59 @@
   
       /**
        * Writes out a Pass record with comment.
  +     * Output only when ConsoleLogger.loggingLevel > FAILSONLY
  +     * 
        * @param comment comment to log with the pass record.
        */
       public void checkPass(String comment)
       {
  +        // Note <=, since FAILSONLY is a special level
  +        if (consoleLoggingLevel <= FAILSONLY)
  +            return;
  +            
           outStream.println(sIndent + "PASS!  " + comment);
       }
   
       /**
        * Writes out an ambiguous record with comment.
  +     * Output only when ConsoleLogger.loggingLevel > FAILSONLY
  +     *
        * @param comment comment to log with the ambg record.
        */
       public void checkAmbiguous(String comment)
       {
  +        // Note <=, since FAILSONLY is a special level
  +        if (consoleLoggingLevel <= FAILSONLY)
  +            return;
  +
           outStream.println(sIndent + "AMBG   " + comment);
       }
   
       /**
        * Writes out a Fail record with comment.
  +     * Output only when ConsoleLogger.loggingLevel >= FAILSONLY
  +     *
        * @param comment comment to log with the fail record.
        */
       public void checkFail(String comment)
       {
  +        if (consoleLoggingLevel < FAILSONLY)
  +            return;
  +
           outStream.println(sIndent + "FAIL   " + comment);
       }
   
       /**
        * Writes out a Error record with comment.
  +     * Output only when ConsoleLogger.loggingLevel >= ERRORMSG
  +     *
        * @param comment comment to log with the error record.
        */
       public void checkErr(String comment)
       {
  +        if (consoleLoggingLevel < ERRORMSG)
  +            return;
  +
           outStream.println(sIndent + "ERROR  " + comment);
       }
   
  @@ -469,12 +572,17 @@
   
       /**
        * Writes out a Pass record with comment and ID.
  -     * @author Shane_Curcuru@lotus.com
  +     * Output only when ConsoleLogger.loggingLevel > FAILSONLY
  +     * 
        * @param comment comment to log with the pass record.
        * @param ID token to log with the pass record.
        */
       public void checkPass(String comment, String id)
       {
  +        // Note <=, since FAILSONLY is a special level
  +        if (consoleLoggingLevel <= FAILSONLY)
  +            return;
  +            
           if (id != null)
               outStream.println(sIndent + "PASS!  (" + id + ") " + comment);
           else
  @@ -483,12 +591,17 @@
   
       /**
        * Writes out an ambiguous record with comment and ID.
  -     * @author Shane_Curcuru@lotus.com
  +     * Output only when ConsoleLogger.loggingLevel > FAILSONLY
  +     * 
        * @param comment to log with the ambg record.
        * @param ID token to log with the pass record.
        */
       public void checkAmbiguous(String comment, String id)
       {
  +        // Note <=, since FAILSONLY is a special level
  +        if (consoleLoggingLevel <= FAILSONLY)
  +            return;
  +            
           if (id != null)
               outStream.println(sIndent + "AMBG   (" + id + ") " + comment);
           else
  @@ -497,12 +610,16 @@
   
       /**
        * Writes out a Fail record with comment and ID.
  -     * @author Shane_Curcuru@lotus.com
  +     * Output only when ConsoleLogger.loggingLevel >= FAILSONLY
  +     * 
        * @param comment comment to log with the fail record.
        * @param ID token to log with the pass record.
        */
       public void checkFail(String comment, String id)
       {
  +        if (consoleLoggingLevel < FAILSONLY)
  +            return;
  +
           if (id != null)
               outStream.println(sIndent + "FAIL!  (" + id + ") " + comment);
           else
  @@ -511,12 +628,16 @@
   
       /**
        * Writes out an Error record with comment and ID.
  -     * @author Shane_Curcuru@lotus.com
  +     * Output only when ConsoleLogger.loggingLevel >= ERRORMSG
  +     * 
        * @param comment comment to log with the error record.
        * @param ID token to log with the pass record.
        */
       public void checkErr(String comment, String id)
       {
  +        if (consoleLoggingLevel < ERRORMSG)
  +            return;
  +
           if (id != null)
               outStream.println(sIndent + "ERROR  (" + id + ") " + comment);
           else