会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
西子吟
我是一个乖乖的小孩
博客园
首页
新随笔
联系
订阅
管理
让velocity使用log4j
捣鼓一下,水贴下代码。看了就明白了。
Code
1
package
velocity;
2
import
log4j.Log4jDemo;
3
import
org.apache.log4j.BasicConfigurator;
4
import
org.apache.log4j.Logger;
5
import
org.apache.log4j.PropertyConfigurator;
6
import
org.apache.velocity.app.VelocityEngine;
7
import
org.apache.velocity.runtime.RuntimeConstants;
8
public
class
VelocityLogDemo
{
9
public
static
String LOGGER_NAME
=
"
velexample
"
;
10
public
static
void
main(String[] args)
throws
Exception
{
11
PropertyConfigurator.configure(
"
src/main/java/velocity/log4j.properties
"
);
12
//
BasicConfigurator.configure();
13
Logger log
=
Logger.getLogger( LOGGER_NAME );
14
log.info(
"
Log4jLoggerExample: ready to start velocity
"
);
15
VelocityEngine ve
=
new
VelocityEngine();
16
ve.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
17
"
org.apache.velocity.runtime.log.Log4JLogChute
"
);
18
ve.setProperty(
"
runtime.log.logsystem.log4j.logger
"
,
19
LOGGER_NAME);
20
ve.init();
21
//
Velocity.init("src/main/java/velocity/velocity.properties");
22
}
23
}
最重要的地方就在于log4j的logger Name,如果没有这个log,那么velocity就无法找到打印的target。
posted @
2009-11-22 22:16
雪霁霜飞
阅读(
623
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告