免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3446 | 回复: 1

Velocity 配置 Log4J 日志输出 [复制链接]

论坛徽章:
0
发表于 2011-05-10 13:52 |显示全部楼层
[代码] Log4jCategoryExample.java
  1. import org.apache.log4j.BasicConfigurator;
  2. import org.apache.log4j.Category;
  3. import org.apache.velocity.app.VelocityEngine;
  4. import org.apache.velocity.runtime.RuntimeConstants;

  5. public class Log4jCategoryExample
  6. {
  7.     public static String CATEGORY_NAME = "velexample";

  8.     public static void main( String args[] )
  9.         throws Exception
  10.     {
  11.         //configure log4j to log to console
  12.         BasicConfigurator.configure();

  13.         Category log = Category.getInstance( CATEGORY_NAME );

  14.         log.info("Hello from Log4jCategoryExample - ready to start velocity");

  15.         VelocityEngine ve = new VelocityEngine();

  16.         ve.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
  17.             "org.apache.velocity.runtime.log.SimpleLog4JLogSystem" );

  18.         ve.setProperty("runtime.log.logsystem.log4j.category", CATEGORY_NAME);

  19.         ve.init();

  20.         log.info("this should follow the initialization output from velocity");
  21.     }
  22. }
复制代码

论坛徽章:
0
发表于 2011-05-11 20:53 |显示全部楼层
学习了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP