2007-02-06
工作日志20070206(昨天安装log4j到机器上的过程。)
关键字: 工作日志
昨天的一下午就是折腾log4j
先写了一个小东西用main来运行
再写一个web用tomcate运行
再用这个web放到ear包中发布到was上面去
累死了。。。还没完
又把log4j的properties分成了
N个log文件用来放不同的日志
忽然发现原来的问题还没解决。。。。。
回去把问题又看了看原来是方言用了hibernate3的现在的是hibernate2的
改完之后一切OK
写好了log4j.properties
放到了src下面
没有反应
放到web_inf/classes下面
还是没反应。。。。
上网看了看大约是没有初始化。。。
所以到
web.xml
定了一个severlet叫initlog用来初始化log4j
web.xml加入这么一行
玩具作到这里差不多了
之后就是大移置工作了。。。
不过还是有很多东西要作。。。。
希望有这点问题不会影响我过年。。。。
先写了一个小东西用main来运行
再写一个web用tomcate运行
再用这个web放到ear包中发布到was上面去
累死了。。。还没完
又把log4j的properties分成了
N个log文件用来放不同的日志
忽然发现原来的问题还没解决。。。。。
回去把问题又看了看原来是方言用了hibernate3的现在的是hibernate2的
改完之后一切OK
写好了log4j.properties
放到了src下面
没有反应
放到web_inf/classes下面
还是没反应。。。。
上网看了看大约是没有初始化。。。
所以到
web.xml
定了一个severlet叫initlog用来初始化log4j
public class InitLog extends HttpServlet
{
public void init()
{ //应用的绝对路径
String prefix = getServletContext().getRealPath("/");
//配置文件中名称得到字符串(内容是log4j.properties的相对路径)
String file = getInitParameter("log4j-config-file");
if(file != null){
PropertyConfigurator.configure(String.valueOf(prefix) + String.valueOf(file));
}
//看看目录树是否拼写是否正确
System.out.println(String.valueOf(prefix) + String.valueOf(file));
Logger logger = Logger.getLogger(this.getClass());
//测试(没办法进行TDD了)
logger.debug("this is debug");
logger.info("this is debug");
logger.error("this is debug");
}
public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
{
}
}
web.xml加入这么一行
<servlet>
<servlet-name>InitLog</servlet-name>
<!--这个是我自己写的初始化的servlet-->
<servlet-class>com.alt.alcargo.web.util.InitLog</servlet-class>
<init-param>
<!--程序中需要的参数,这个名子不好-->
<param-name>log4j-config-file</param-name>
<param-value>\WEB-INF\resource\log4j.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
玩具作到这里差不多了
之后就是大移置工作了。。。
不过还是有很多东西要作。。。。
希望有这点问题不会影响我过年。。。。
评论
ddbird
2007-02-28
我的tomcat只用了个log4j.xml 和log4j.dtd就有日志了,好像不用配置一个专门的init servlet。
dickwin
2007-02-08
public void init() throws ServletException
{
super.init();
String fileName = getInitParameter("log4j-init-file");
String prefix = getServletContext().getRealPath("/");
System.out.println("file name is:" + fileName);
if(fileName != null)
{
PropertyConfigurator.configure(prefix+fileName);
logger.debug("Init Log4j success!");
}
else
{
BasicConfigurator.configure();
logger.debug("no property file found!, basic setting for log4j");
}[/code]
{
super.init();
String fileName = getInitParameter("log4j-init-file");
String prefix = getServletContext().getRealPath("/");
System.out.println("file name is:" + fileName);
if(fileName != null)
{
PropertyConfigurator.configure(prefix+fileName);
logger.debug("Init Log4j success!");
}
else
{
BasicConfigurator.configure();
logger.debug("no property file found!, basic setting for log4j");
}[/code]
发表评论
- 浏览: 216108 次
- 性别:

- 来自: 北京

- 详细资料
搜索本博客
我的相册
长椅
共 39 张
共 39 张
最近加入圈子
链接
最新评论
-
到底要招什么样子的人?
那到底要什么样的人啊?你的重点呢?你想表达什么?
-- by xiaoyi829 -
到底要招什么样子的人?
努力吧!什么都是从不懂到懂,懂到精通!
-- by ada1230 -
DBA数据库字典
懒人。。。半仙。。。
-- by YuLimin -
天狗食日
看了。。。英雄(美剧)。。。。 之后就非常想要见识一下日食了 谢谢
-- by 抛出异常的爱 -
天狗食日
按照月亮运行规律来讲,一个月就会出现一次日食,并且今年出现日食时间和明年差不多, ...
-- by ddd






评论排行榜