You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by ge...@apache.org on 2001/03/19 06:18:30 UTC

cvs commit: jakarta-velocity/src/java/org/apache/velocity/runtime/log LogManager.java

geirm       01/03/18 21:18:30

  Modified:    src/java/org/apache/velocity/runtime/log LogManager.java
  Log:
  Now creates a logger according to the following rules :
  
  1) First see if a living logger was placed in the configuration (so an app
    can have Vel log into its log system, it if wants...)
  2) If not, try to create from the class specified in the configuration.
  3) If that fails (it shouldn't, as the AvalongLogSystem is in the default
     properties) then it just makes an AvalonLogSystem
  
  Revision  Changes    Path
  1.4       +49 -7     jakarta-velocity/src/java/org/apache/velocity/runtime/log/LogManager.java
  
  Index: LogManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/log/LogManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LogManager.java	2001/03/12 07:19:53	1.3
  +++ LogManager.java	2001/03/19 05:18:29	1.4
  @@ -54,6 +54,7 @@
    * <http://www.apache.org/>.
    */
   
  +import org.apache.velocity.runtime.Runtime;
   
   /**
    * LogManager.java
  @@ -63,19 +64,60 @@
    *
    * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
  - * @version $Id: LogManager.java,v 1.3 2001/03/12 07:19:53 jon Exp $
  + * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
  + * @version $Id: LogManager.java,v 1.4 2001/03/19 05:18:29 geirm Exp $
    */
   public class LogManager
   {
       /**
  -     * This class should be fixed to get its log system from
  -     * a properties file.
  +     *  Creates a new logging system.  Uses the property
  +     *  RUNTIME_LOG_LOGSYSTEM_CLASS as the class to create.
  +     *  Note that the class created has to do its own
  +     *  initialization - there is no init() method called/
        */
  -    public static LogSystem createLogSystem(String logFile)
  +    public static LogSystem createLogSystem()
           throws Exception
       {
  -        LogSystem ls = new AvalonLogSystem();
  -        ls.init(logFile);
  -        return ls;
  +        /*
  +         *  if a logSystem was set as a configuation value, use that
  +         */
  +        
  +        Object o = Runtime.getProperty( Runtime.RUNTIME_LOG_LOGSYSTEM );
  +
  +        if ( o instanceof LogSystem)
  +        {
  +            return (LogSystem) o;
  +        }
  +  
  +        /*
  +         *  otherwise, see if a class was specified
  +         */
  +
  +        String claz = (String) Runtime.getProperty( Runtime.RUNTIME_LOG_LOGSYSTEM_CLASS );
  +        
  +        if (claz != null || claz.length() > 0 )
  +        {
  +            o = Class.forName( claz ).newInstance();
  +
  +            if (o instanceof LogSystem)
  +            {
  +                return (LogSystem) o;
  +            }
  +            else
  +            {
  +                Runtime.error("The specifid logger class " + claz + " isn't a valid LogSystem\n");
  +            }
  +        }
  +      
  +        /*
  +         *  if the above failed, then 
  +         *  make an Avalon log system
  +         */
  +        
  +        AvalonLogSystem als = new AvalonLogSystem();
  +        
  +        return als;
  +        
       }
   }
  +