I meant when I stop and start the server.

In any case, I figured out the problem.  Apparently log4j expects the
String representing the file path to have its path separators escaped.  In
other words the string i was passing in looked something like this "c:
\jakarta4\webapps..." and it expects "c:\\jakarta4\\webapps...".  The code
I sent before should be revised to look like this (if using jdk1.4, you can
use regexp):

StringBuffer fileName = new StringBuffer(getServletContext().getRealPath
("/WEB-INF/logs") + "\\test.log");

for (int i = 0 ; i < fileName.length() ; i++){
  if ( fileName.charAt(i) == '\\'){
     fileName.insert(i, '\\');
     i++;  //jump ahead - infinite loop otherwise
  }
}

System.setProperty("logFile.name", fileName.toString());

Now everything works fine.

Ceki, in jdk1.4 logging, you specify file paths by using the forward slash
which is then replaced by them to use the system file separator.  Does
log4j envisage something like that?  Do you think the code listed above is
future-version safe?

Isaac



                                                                                       
     
                    Ceki Gülcü                                                         
     
                    <[EMAIL PROTECTED]>        To:     "Log4J Users List"                    
     
                                          <[EMAIL PROTECTED]>              
     
                    07/24/2002           cc:                                           
     
                    10:57 AM             Subject:     Re: Can anyone explain this?     
     
                    Please respond                                                     
     
                    to "Log4J                                                          
     
                    Users List"                                                        
     
                                                                                       
     
                                                                                       
     




At 10:27 24.07.2002 -0400, you wrote:
>Hi.
>
>I need to dynamically define the name of my RollingFileAppender (We have
>amny environments and I don't want to have to keep on changing the config
>file).  Since I also don't want the headache of maintaining system
>properties I decided on doing it via the code as follows:
>
>System.setProperty("logFile.name", getServletContext().getRealPath
>("/WEB-INF/logs") + "\\test.log");
>
>The config file looks like this:
>
><appender name="A2" class="org.apache.log4j.DailyRollingFileAppender">
>    <param name="Append" value="true"/>
>    <param name="File" value="${logFile.name}"/>
>....
>
>This works because all our environments conform to the Servlets 2.1
>directory specs.
>
>What's wierd is that even though I define the "Append" attribute to
"true",
>log4j still truncates the file each time the servlet engine is bounced
--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to