This is a toy demonstration of how Velocity can use an externally configured logger : Velocity记录 « Velocity « Java

En
Java
1. 图形用户界面
2. 三维图形动画
3. 高级图形
4. 蚂蚁编译
5. Apache类库
6. 统计图
7. 
8. 集合数据结构
9. 数据类型
10. 数据库JDBC
11. 设计模式
12. 开发相关类
13. EJB3
14. 电子邮件
15. 事件
16. 文件输入输出
17. 游戏
18. 泛型
19. GWT
20. Hibernate
21. 本地化
22. J2EE平台
23. 基于J2ME
24. JDK-6
25. JNDI的LDAP
26. JPA
27. JSP技术
28. JSTL
29. 语言基础知识
30. 网络协议
31. PDF格式RTF格式
32. 映射
33. 常规表达式
34. 脚本
35. 安全
36. Servlets
37. Spring
38. Swing组件
39. 图形用户界面
40. SWT-JFace-Eclipse
41. 线程
42. 应用程序
43. Velocity
44. Web服务SOA
45. 可扩展标记语言
Java 教程
Java » Velocity » Velocity记录屏幕截图 
This is a toy demonstration of how Velocity can use an externally configured logger

/*
 * Copyright 2000-2001,2004 The Apache Software Foundation.
 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 
 *      http://www.apache.org/licenses/LICENSE-2.0
 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.apache.velocity.app.Velocity;
import org.apache.velocity.runtime.log.LogSystem;
import org.apache.velocity.runtime.RuntimeServices;


/**
 *  This is a toy demonstration of how Velocity
 *  can use an externally configured logger.  In 
 *  this example, the class using Velocity
 *  implements Velocity's logger interface, and
 *  all Velocity log messages are funneled back
 *  through it.
 *
 @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
 @version $Id: LoggerExample.java,v 1.2.10.1 2004/03/04 00:18:29 geirm Exp $
 */
public class LoggerExample implements LogSystem
{
    public LoggerExample()
    {
        try
        {
            /*
             *  this class implements the LogSystem interface, so we
             *  can use it as a logger for Velocity
             */
            
            Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, this );
            Velocity.init();

            /*
             *  that will be enough.  The Velocity initialization will be 
             *  output to stdout because of our
             *  logVelocityMessage() method in this class
             */
        }
        catchException e )
        {
            System.out.println("Exception : " + e);
        }
    }

  /**
   *  Required init() method for LogSystem
   *  to get access to RuntimeServices
   */ 
   public void initRuntimeServices rs )
   {
     return;
   }
   
    /**
     *  This is the key method needed to implement a logging interface
     *  for Velocity.
     */ 
    public void logVelocityMessage(int level, String message)
    {
        System.out.println("level : " + level + " msg : " + message);
    }

    public static void main(String[] args)
    {
        LoggerExample t = new LoggerExample();
    }
}

           
       
velocity-Externally-Configured-logger.zip( 2,191 k)
Related examples in the same category
1. 控制台登录系统
2. Velocity自定义日志
3. How to use an existing Log4j Category as the Velocity logging target
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.