`
抛出异常的爱
  • 浏览: 620057 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

工作日志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
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> 




玩具作到这里差不多了
之后就是大移置工作了。。。
不过还是有很多东西要作。。。。


希望有这点问题不会影响我过年。。。。
分享到:
评论
2 楼 ddbird 2007-02-28  
我的tomcat只用了个log4j.xml 和log4j.dtd就有日志了,好像不用配置一个专门的init servlet。
1 楼 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");
         }

相关推荐

Global site tag (gtag.js) - Google Analytics