What's weird is that if the escaped backslashes are needed, why does the file get written to in the first place? Log4j , obviously, finds the file and is able to write to it. The "Append" thing doesn't, on the face of it, seem like it should be related to using escaped backslashes or not.
A real explanation of what is going on here is definitely needed. I use a similar mechanism for setting the path to log files in servlets, but I use a regular FileAppender and have Append set to false, so I've never experienced this bug. However, if I make the switch to Appending the file, I'd sure like it to work, so I'd definitely be interested in whether I'd be required to use Isaac's work-around. Jake Wednesday, July 24, 2002, 10:15:15 AM, you wrote: IGnfo> I meant when I stop and start the server. IGnfo> In any case, I figured out the problem. Apparently log4j expects the IGnfo> String representing the file path to have its path separators escaped. In IGnfo> other words the string i was passing in looked something like this "c: IGnfo> \jakarta4\webapps..." and it expects "c:\\jakarta4\\webapps...". The code IGnfo> I sent before should be revised to look like this (if using jdk1.4, you can IGnfo> use regexp): IGnfo> StringBuffer fileName = new StringBuffer(getServletContext().getRealPath IGnfo> ("/WEB-INF/logs") + "\\test.log"); IGnfo> for (int i = 0 ; i < fileName.length() ; i++){ IGnfo> if ( fileName.charAt(i) == '\\'){ IGnfo> fileName.insert(i, '\\'); IGnfo> i++; //jump ahead - infinite loop otherwise IGnfo> } IGnfo> } IGnfo> System.setProperty("logFile.name", fileName.toString()); IGnfo> Now everything works fine. IGnfo> Ceki, in jdk1.4 logging, you specify file paths by using the forward slash IGnfo> which is then replaced by them to use the system file separator. Does IGnfo> log4j envisage something like that? Do you think the code listed above is IGnfo> future-version safe? IGnfo> Isaac IGnfo> Ceki Gülcü IGnfo> <[EMAIL PROTECTED]> To: "Log4J Users List" IGnfo> <[EMAIL PROTECTED]> IGnfo> 07/24/2002 cc: IGnfo> 10:57 AM Subject: Re: Can anyone explain this? IGnfo> Please respond IGnfo> to "Log4J IGnfo> Users List" IGnfo> 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 IGnfo> "true", >>log4j still truncates the file each time the servlet engine is bounced IGnfo> -- IGnfo> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> IGnfo> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- Best regards, Jacob mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>