geirm       01/11/18 18:05:56

  Added:       contrib/temporary/stderrlogsystem README.txt
                        StderrLogSystem.java Test.java
  Log:
  Standard error logger donated by Christoph Reck <[EMAIL PROTECTED]>
  
  Also including a simple Test program to show how it works.
  
  Revision  Changes    Path
  1.1                  jakarta-velocity/contrib/temporary/stderrlogsystem/README.txt
  
  Index: README.txt
  ===================================================================
  Contributed by Christoph Reck <[EMAIL PROTECTED]> with the
  following [edited] message to the user list :
  
  For anyone interested, I've created a simple StderrLogSystem as a 
  drop-in for Velocity - see attachment. Either it can be taken into
  the velocity contribution section, or put into velocity as the
  standard logger, or you can change the package name to whatever
  you want and include it in your distribution.
  
  The reason for this is that I do not want stray files created
  (velocity.log) in my file system when running my Anakia commandline
  tool.
  
  I use it as follows:
  
  within main()
      // The classname of the default logger to be used
      String loggerClass =
        "StderrLogSystem";
  
      Vector vargs = new Vector();
      for( int i = 0; i < args.length; ++i )
      {
        if( args[i].equals("-quiet") )
          loggerClass = "org.apache.velocity.runtime.log.NullLogSystem";
        else if( args[i].equals("-verbose") )
          loggerClass = "StderrLogSystem";
        else
          vargs.add( args[i] );
      }
  
  and for the ve.init():
      templatePath = new File(templatePath).getCanonicalPath();
      velocity = new VelocityEngine();
      velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatePath);
      velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, loggerClass);
      velocity.init();
  NOTE: templatePath is "." for my current XmlTransformer batch tool.
  
  
  [Note - Class was removed from package for ease of demonstration 
  here in the contrib section - geir ]
  
  
  
  1.1                  
jakarta-velocity/contrib/temporary/stderrlogsystem/StderrLogSystem.java
  
  Index: StderrLogSystem.java
  ===================================================================
  
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.velocity.runtime.RuntimeServices;
  import org.apache.velocity.runtime.RuntimeConstants;
  
  import org.apache.velocity.runtime.log.LogSystem;
  
  /**
   * Implementation of a Simple logger to output messages to STDERR.
   *
   * @author    <a href="mailto:[EMAIL PROTECTED]";>Christoph Reck</a>
   * @version   $Id: StderrLogSystem.java,v 1.1 2001/11/19 02:05:56 geirm Exp $
   */
  public class StderrLogSystem implements LogSystem
  {
      /**
       * Empty constructor.
       */
      public StderrLogSystem()
      {
          // nothing to do
      }
      
      /**
       * Do the initialization (this logger does not do anything here).
       */
      public void init( RuntimeServices rs ) throws Exception
      {
          // nothing to do
      }
      
      /**
       * Does the acutal message logging.
       *
       * @param level    severity level
       * @param message  complete error message
       */
      public void logVelocityMessage( int level, String message )
      {
          switch ( level )
          {
          case LogSystem.WARN_ID:
              System.err.println( RuntimeConstants.WARN_PREFIX + message );
              break;
          case LogSystem.INFO_ID:
              System.err.println( RuntimeConstants.INFO_PREFIX + message );
              break;
          case LogSystem.DEBUG_ID:
              System.err.println( RuntimeConstants.DEBUG_PREFIX + message );
              break;
          case LogSystem.ERROR_ID:
              System.err.println( RuntimeConstants.ERROR_PREFIX + message );
              break;
          default:
              System.err.println( message );
              break;
          }
      }
  }
  
  
  
  1.1                  jakarta-velocity/contrib/temporary/stderrlogsystem/Test.java
  
  Index: Test.java
  ===================================================================
  
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.velocity.app.VelocityEngine;
  
  /**
   *  simple class to demonstrate how to use the
   *  StderrLogSystem.  It doesn't do anything but
   *  setup and init(), but that should produce
   *  enough output...
   *
   *  @author <a href="[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
   *  @version $Id: Test.java,v 1.1 2001/11/19 02:05:56 geirm Exp $
   */
  public class Test
  {
      Test()
      {
          VelocityEngine ve = new VelocityEngine();
  
          ve.setProperty("runtime.log.logsystem.class", "StderrLogSystem");
  
          try
          {
              ve.init();
          }
          catch(Exception e )
          {
              System.out.println( e );
          }
      }
  
      public static void main( String args[] )
      {
          Test t = new Test();
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to