/**
 * Copyright (c) 2003-2004 System Integrator Corporation.
 *                 All Rights Reserved.
 */
package jp.co.sint.logutil;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jp.co.sint.config.SIConfig;
import jp.co.sint.tools.SIUtil;

/**
 * LOG4J用のConfigファイルを読んで、パラメータの設定の取得
 * @version $Id: SILog4jInit.java,v 1.0 2003/06/18 jwchen Exp $
 * @author  Jinwang Chen
 */

public class SILog4jInit extends HttpServlet{
  ServletContext context;

  public void init(ServletConfig config) {
    try {
      super.init(config);
      context=config.getServletContext();
      String fileName = getRealPath(config.getInitParameter("log4jConfig"));
      SIConfig.SILOG4J_DEFAULT_CONFIG_FILE_NAME=fileName;
      SILogConfig.loadConfigFile(SIConfig.SILOG4J_DEFAULT_CONFIG_FILE_NAME);
      System.out.println(fileName+" was loaded.Logger started ");
    }catch(Exception e){
      e.printStackTrace();
    }
  }

  public String getRealPath(String lPath){
    if (SIUtil.isNull(lPath))lPath="/";
	if (!lPath.trim().startsWith("/"))lPath="/"+lPath.trim();
	return context.getRealPath(lPath);
  }

  public void doGet(HttpServletRequest requset, HttpServletResponse response){}
  public void doPost(HttpServletRequest requset, HttpServletResponse response){}
}