You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by nb...@apache.org on 2006/10/10 22:40:05 UTC

svn commit: r462551 - in /jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log: LogManager.java StandardOutLogChute.java SystemLogChute.java

Author: nbubna
Date: Tue Oct 10 13:40:04 2006
New Revision: 462551

URL: http://svn.apache.org/viewvc?view=rev&rev=462551
Log:
replace inflexible and possibly problematic StandardOutLogChute with SystemLogChute that can by default prints to System.err but can be configured to split or wholly redirect output to System.out by log level

Added:
    jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/SystemLogChute.java
      - copied, changed from r462541, jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/StandardOutLogChute.java
Removed:
    jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/StandardOutLogChute.java
Modified:
    jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/LogManager.java

Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/LogManager.java
URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/LogManager.java?view=diff&rev=462551&r1=462550&r2=462551
==============================================================================
--- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/LogManager.java (original)
+++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/LogManager.java Tue Oct 10 13:40:04 2006
@@ -46,7 +46,7 @@
  *       as all three are listed as defaults.
  *  </li>
  *  <li>
- *      Finally, we turn to the System.out stream and print log messages
+ *      Finally, we turn to the System.err stream and print log messages
  *      to it if nothing else works.
  *  </li>
  *
@@ -184,11 +184,11 @@
          * problems for the default loggers, log4j and Java1.4+.
          * Since we really don't know and we want to be sure the user knows
          * that something went wrong with the logging, let's fall back to the
-         * surefire StandardOutLogChute. No panicking or failing to log!!
+         * surefire SystemLogChute. No panicking or failing to log!!
          */
-        LogChute slc = new StandardOutLogChute();
+        LogChute slc = new SystemLogChute();
         slc.init(rsvc);
-        log.debug("Using StandardOutLogChute.");
+        log.debug("Using SystemLogChute.");
         return slc;
     }
 

Copied: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/SystemLogChute.java (from r462541, jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/StandardOutLogChute.java)
URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/SystemLogChute.java?view=diff&rev=462551&p1=jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/StandardOutLogChute.java&r1=462541&p2=jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/SystemLogChute.java&r2=462551
==============================================================================
--- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/StandardOutLogChute.java (original)
+++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/log/SystemLogChute.java Tue Oct 10 13:40:04 2006
@@ -19,22 +19,22 @@
 import org.apache.velocity.runtime.RuntimeServices;
 
 /**
- * Logger used when no other is configured.
+ * Logger used when no other is configured.  By default, all messages
+ * will be printed to the System.err output stream.
  *
  * @author <a href="mailto:nbubna@apache.org">Nathan Bubna</a>
  * @version $Id$
  */
-public class StandardOutLogChute implements LogChute
+public class SystemLogChute implements LogChute
 {
-    /** */
-    public static final String RUNTIME_LOG_LEVEL_KEY =
-        "runtime.log.logsystem.stdout.level";
+    public static final String RUNTIME_LOG_LEVEL_KEY = 
+        "runtime.log.logsystem.system.level";
+    public static final String RUNTIME_LOG_SYSTEM_ERR_LEVEL_KEY = 
+        "runtime.log.logsystem.system.err.level";
 
     private int enabled = TRACE_ID;
+    private int errLevel = TRACE_ID;
 
-    /**
-     * @see org.apache.velocity.runtime.log.LogChute#init(org.apache.velocity.runtime.RuntimeServices)
-     */
     public void init(RuntimeServices rs) throws Exception
     {
         // look for a level config property
@@ -42,29 +42,40 @@
         if (level != null)
         {
             // and set it accordingly
-            if (level.equalsIgnoreCase("debug"))
-            {
-                setEnabledLevel(DEBUG_ID);
-            }
-            else if (level.equalsIgnoreCase("info"))
-            {
-                setEnabledLevel(INFO_ID);
-            }
-            else if (level.equalsIgnoreCase("warn"))
-            {
-                setEnabledLevel(WARN_ID);
-            }
-            else if (level.equalsIgnoreCase("error"))
-            {
-                setEnabledLevel(ERROR_ID);
-            }
+            setEnabledLevel(toLevel(level));
+        }
+
+        // look for an errLevel config property
+        String errLevel = (String)rs.getProperty(RUNTIME_LOG_SYSTEM_ERR_LEVEL_KEY);
+        if (errLevel != null)
+        {
+            setSystemErrLevel(toLevel(errLevel));
+        }
+    }
+
+    protected int toLevel(String level) {
+        if (level.equalsIgnoreCase("debug"))
+        {
+            return DEBUG_ID;
+        }
+        else if (level.equalsIgnoreCase("info"))
+        {
+            return INFO_ID;
+        }
+        else if (level.equalsIgnoreCase("warn"))
+        {
+            return WARN_ID;
+        }
+        else if (level.equalsIgnoreCase("error"))
+        {
+            return ERROR_ID;
+        }
+        else
+        {
+            return TRACE_ID;
         }
     }
 
-    /**
-     * @param level
-     * @return The prefix for the given level.
-     */
     protected String getPrefix(int level)
     {
         switch (level)
@@ -100,9 +111,9 @@
     /**
      * Logs messages to the system console so long as the specified level
      * is equal to or greater than the level this LogChute is enabled for.
-     * If the level is equal to or greater than LogChute.ERROR_ID,
-     * messages will be printed to System.err. Otherwise, they will be
-     * printed to System.out. If a java.lang.Throwable accompanies the
+     * If the level is equal to or greater than LogChute.ERROR_ID, 
+     * messages will be printed to System.err. Otherwise, they will be 
+     * printed to System.out. If a java.lang.Throwable accompanies the 
      * message, it's stack trace will be printed to the same stream
      * as the message.
      *
@@ -118,7 +129,7 @@
         }
 
         String prefix = getPrefix(level);
-        if (level > 2)
+        if (level >= this.errLevel)
         {
             System.err.print(prefix);
             System.err.println(message);
@@ -142,7 +153,6 @@
 
     /**
      * Set the minimum level at which messages will be printed.
-     * @param level
      */
     public void setEnabledLevel(int level)
     {
@@ -151,7 +161,6 @@
 
     /**
      * Returns the current minimum level at which messages will be printed.
-     * @return The current minimum level at which messages will be printed.
      */
     public int getEnabledLevel()
     {
@@ -159,11 +168,27 @@
     }
 
     /**
+     * Set the minimum level at which messages will be printed to System.err
+     * instead of System.out.
+     */
+    public void setSystemErrLevel(int level)
+    {
+        this.enabled = level;
+    }
+
+    /**
+     * Returns the current minimum level at which messages will be printed
+     * to System.err instead of System.out.
+     */
+    public int getSystemErrLevel()
+    {
+        return this.enabled;
+    }
+
+    /**
      * This will return true if the specified level
      * is equal to or higher than the level this
      * LogChute is enabled for.
-     * @param level
-     * @return True if logging is enabled for this level.
      */
     public boolean isLevelEnabled(int level)
     {



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


Re: svn commit: r462551 - in

Posted by "Henning P. Schmiedehausen" <hp...@intermeta.de>.
nbubna@apache.org writes:

>URL: http://svn.apache.org/viewvc?view=rev&rev=462551
>Log:
>replace inflexible and possibly problematic StandardOutLogChute with SystemLogChute that can by default prints to System.err but can be configured to split or wholly redirect output to System.out by log level


+1! Thanks Nathan!

	Best regards
		Henning

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
hps@intermeta.de        +49 9131 50 654 0   http://www.intermeta.de/

RedHat Certified Engineer -- Jakarta Turbine Development  -- hero for hire
   Linux, Java, perl, Solaris -- Consulting, Training, Development

Social behaviour: Bavarians can be extremely egalitarian and folksy.
                                    -- http://en.wikipedia.org/wiki/Bavaria
Most Franconians do not like to be called Bavarians.
                                    -- http://en.wikipedia.org/wiki/Franconia

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