Author: kkolinko Date: Mon Jul 11 16:46:28 2011 New Revision: 1145237 URL: http://svn.apache.org/viewvc?rev=1145237&view=rev Log: * JULI FileHandler, AccessLogValve: Create a directory automatically when it is specified as a part of the file name, e.g. in the prefix attribute. Earlier this happened only if it was specified with the directory attribute. * AccessLogValve: Log a failure if access log file cannot be opened.
Modified: tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java tomcat/trunk/java/org/apache/catalina/valves/LocalStrings.properties tomcat/trunk/java/org/apache/juli/FileHandler.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java?rev=1145237&r1=1145236&r2=1145237&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java (original) +++ tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java Mon Jul 11 16:46:28 2011 @@ -1008,36 +1008,44 @@ public class AccessLogValve extends Valv } // Open the current log file - try { - String pathname; - // If no rotate - no need for dateStamp in fileName - if (rotatable) { - pathname = dir.getAbsolutePath() + File.separator + prefix - + dateStamp + suffix; - } else { - pathname = dir.getAbsolutePath() + File.separator + prefix - + suffix; - } - Charset charset = null; - if (encoding != null) { - try { - charset = B2CConverter.getCharset(encoding); - } catch (UnsupportedEncodingException ex) { - log.error(sm.getString( - "accessLogValve.unsupportedEncoding", encoding), ex); - } + File pathname; + // If no rotate - no need for dateStamp in fileName + if (rotatable) { + pathname = new File(dir.getAbsoluteFile(), prefix + dateStamp + + suffix); + } else { + pathname = new File(dir.getAbsoluteFile(), prefix + suffix); + } + File parent = pathname.getParentFile(); + if (!parent.exists()) { + if (!parent.mkdirs()) { + log.error(sm.getString("accessLogValve.openDirFail", parent)); } - if (charset == null) { - charset = Charset.defaultCharset(); + } + + Charset charset = null; + if (encoding != null) { + try { + charset = B2CConverter.getCharset(encoding); + } catch (UnsupportedEncodingException ex) { + log.error(sm.getString( + "accessLogValve.unsupportedEncoding", encoding), ex); } + } + if (charset == null) { + charset = Charset.defaultCharset(); + } + + try { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter( new FileOutputStream(pathname, true), charset), 128000), false); - currentLogFile = new File(pathname); + currentLogFile = pathname; } catch (IOException e) { writer = null; currentLogFile = null; + log.error(sm.getString("accessLogValve.openFail", pathname), e); } } Modified: tomcat/trunk/java/org/apache/catalina/valves/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/LocalStrings.properties?rev=1145237&r1=1145236&r2=1145237&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/valves/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/catalina/valves/LocalStrings.properties Mon Jul 11 16:46:28 2011 @@ -22,7 +22,8 @@ cometConnectionManagerValve.event=Except cometConnectionManagerValve.listenerEvent=Exception processing session listener event # Access log valve -accessLogValve.closeFail=Failed to close log file +accessLogValve.openFail=Failed to open access log file [{0}] +accessLogValve.closeFail=Failed to close access log file accessLogValve.openDirFail=Failed to create directory [{0}] for access logs accessLogValve.rotateFail=Failed to rotate access log accessLogValve.invalidLocale=Failed to set locale to [{0}] Modified: tomcat/trunk/java/org/apache/juli/FileHandler.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/juli/FileHandler.java?rev=1145237&r1=1145236&r2=1145237&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/juli/FileHandler.java (original) +++ tomcat/trunk/java/org/apache/juli/FileHandler.java Mon Jul 11 16:46:28 2011 @@ -367,8 +367,12 @@ public class FileHandler // Open the current log file writerLock.writeLock().lock(); try { - String pathname = dir.getAbsolutePath() + File.separator + - prefix + (rotatable ? date : "") + suffix; + File pathname = new File(dir.getAbsoluteFile(), prefix + + (rotatable ? date : "") + suffix); + File parent = pathname.getParentFile(); + if (!parent.exists()) { + parent.mkdirs(); + } String encoding = getEncoding(); FileOutputStream fos = new FileOutputStream(pathname, true); OutputStream os = bufferSize>0?new BufferedOutputStream(fos,bufferSize):fos; Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1145237&r1=1145236&r2=1145237&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Mon Jul 11 16:46:28 2011 @@ -79,6 +79,15 @@ When generating access logs for errors, log at the Context/Host level if a Context or Host can be identified for the failed request. (markt) </fix> + <update> + In JULI FileHandler and in AccessLogValve create a directory + automatically when it is specified as a part of the file name, e.g. in + the <code>prefix</code> attribute. Earlier this happened only if it was + specified with the <code>directory</code> attribute. (kkolinko) + </update> + <fix> + Log a failure if access log file cannot be opened. (kkolinko) + </fix> </changelog> </subsection> <subsection name="Coyote"> @@ -109,7 +118,7 @@ <subsection name="Cluster"> <changelog> <update> - Remove unnecessary serverl.xml parsing code for old cluster + Remove unnecessary server.xml parsing code for old cluster implementation that does not ship as part of Tomcat 7. (markt) </update> </changelog> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org