jvanzyl     00/10/09 14:43:43

  Modified:    src/java/org/apache/velocity/runtime Runtime.java
  Log:
  - added initializeLogger() method to allow an external mechanism
    to set the path to the log file. for use in conjuction with the
    velocity service for turbine.
  
  Revision  Changes    Path
  1.10      +29 -11    
jakarta-velocity/src/java/org/apache/velocity/runtime/Runtime.java
  
  Index: Runtime.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/Runtime.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Runtime.java      2000/10/09 20:32:18     1.9
  +++ Runtime.java      2000/10/09 21:43:42     1.10
  @@ -110,6 +110,7 @@
       private static Logger logger;
       private static Parser parser;
       private static boolean initialized;
  +    private static StringBuffer pendingMessages = new StringBuffer();
   
       public synchronized static void init(String properties)
           throws Exception
  @@ -125,6 +126,7 @@
                   initializeParserPool();
                   
                   info("Velocity successfully started.");
  +                
                   initialized = true;
               }
               catch (Exception e)
  @@ -140,16 +142,24 @@
           Configuration.setProperty(key, value);
       }        
   
  -    private static void initializeLogger() throws
  +    public static void initializeLogger() throws
           MalformedURLException
       {
  -        // Initialize the logger.
  -        logger = LogKit.createLogger("velocity", 
  -            getString(RUNTIME_LOG), "DEBUG");
  +        if (!getString(TEMPLATE_PATH).equals("system"))
  +        {
  +            // Initialize the logger.
  +            logger = LogKit.createLogger("velocity", 
  +                getString(RUNTIME_LOG), "DEBUG");
                   
  -        LogTarget[] t = logger.getLogTargets();            
  -        ((FileOutputLogTarget)t[0])
  -            .setFormat("%5.5{time} %{message}\\n%{throwable}" );
  +            LogTarget[] t = logger.getLogTargets();            
  +            ((FileOutputLogTarget)t[0])
  +                .setFormat("%5.5{time} %{message}\\n%{throwable}" );
  +        
  +            if (pendingMessages.length() > 0)
  +            {
  +                logger.info(pendingMessages.toString());
  +            }
  +        }
       }
   
       /**
  @@ -217,24 +227,32 @@
   
       // Runtime logging methods.
   
  +    private static void log(String message)
  +    {
  +        if (logger != null)
  +            logger.info(message);
  +        else
  +            pendingMessages.append(message);
  +    }
  +
       public static void warn(Object message)
       {
  -        logger.warn(WARN + message.toString());
  +        log(WARN + message.toString());
       }
       
       public static void info(Object message)
       {
  -        logger.info(INFO + message.toString());
  +        log(INFO + message.toString());
       }
       
       public static void error(Object message)
       {
  -        logger.error(ERROR + message.toString());
  +        log(ERROR + message.toString());
       }
       
       public static void debug(Object message)
       {
           if (DEBUG_ON)
  -            logger.debug(DEBUG + message.toString());
  +            log(DEBUG + message.toString());
       }
   }
  
  
  

Reply via email to