hoju        2003/08/26 16:00:11

  Modified:    src/java/org/apache/log4j/servlet InitServlet.java
  Log:
  Update InitServlet with updated code from InitContextListener.  I really need to put 
this into a separate class that can be shared between these two configurations.
  
  Jake
  
  Revision  Changes    Path
  1.9       +23 -3     
jakarta-log4j-sandbox/src/java/org/apache/log4j/servlet/InitServlet.java
  
  Index: InitServlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/servlet/InitServlet.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- InitServlet.java  26 Aug 2003 15:42:12 -0000      1.8
  +++ InitServlet.java  26 Aug 2003 23:00:11 -0000      1.9
  @@ -134,17 +134,18 @@
     private static final String PARAM_LOG4J_PREF_SELECTOR = "log4j-selector";
   
     /**
  -   * relative path to config file within current webapp
  +   * relative path to config file within current webapp config param
      */
     private static final String PARAM_LOG4J_CONFIG_PATH = "log4j-config";
   
     /**
  -   * config file re-reading specified in milliseconds
  +   * config file re-reading specified in milliseconds config param
      */
     private static final String PARAM_LOG4J_WATCH_INTERVAL = "log4j-cron";
   
     /**
      * path to be read from a log4j xml config file as a system property
  +   * config param
      */
     private static final String PARAM_LOG4J_LOG_HOME = "log4j-log-home";
   
  @@ -389,13 +390,32 @@
         File logHomeDir = new File(logHome);
   
         if (logHomeDir.exists() || logHomeDir.mkdirs()) {
  -        String tempdir =
  +        /*String tempdir =
             "" + context.getAttribute("javax.servlet.context.tempdir");
           int lastSlash = tempdir.lastIndexOf(File.separator);
   
           if ((tempdir.length() - 1) > lastSlash) {
             logHomePropName = tempdir.substring(lastSlash + 1) + ".log.home";
  +        }*/
  +        String contextPath = "";
  +
  +        try {
  +          //use a more standard way to obtain the context path name
  +          //which should work across all servers.  The tmpdir technique
  +          //(above) depends upon the naming scheme that Tomcat uses.
  +          String path = context.getResource("/").getPath();
  +
  +          //first remove trailing slash, then take what's left over
  +          //which should be the context path less the preceeding
  +          //slash such as "MyContext"
  +          contextPath = path.substring(0, path.lastIndexOf("/"));
  +          contextPath =
  +            contextPath.substring(contextPath.lastIndexOf("/") + 1);
  +        } catch (Exception e) {
  +          ;
           }
  +
  +        logHomePropName = contextPath + ".log.home";
         }
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to