From 32a53ef0a3bcd39ae1f112a8a6b27a59cc31283e Mon Sep 17 00:00:00 2001
From: kkolinko null, the
+ * system default character set will be used. An empty string will be
+ * treated as null when this property is assigned.
+ */
+ protected String encoding = null;
+
/**
* Array of AccessLogElement, they will be used to make log message.
*/
@@ -786,6 +797,29 @@ public class AccessLogValve extends ValveBase implements AccessLog {
locale = findLocale(localeName, locale);
}
+ /**
+ * Return the character set name that is used to write the log file.
+ *
+ * @return Character set name, or null if the system default
+ * character set is used.
+ */
+ public String getEncoding() {
+ return encoding;
+ }
+
+ /**
+ * Set the character set that is used to write the log file.
+ *
+ * @param encoding The name of the character set.
+ */
+ public void setEncoding(String encoding) {
+ if (encoding != null && encoding.length() > 0) {
+ this.encoding = encoding;
+ } else {
+ this.encoding = null;
+ }
+ }
+
// --------------------------------------------------------- Public Methods
/**
@@ -984,9 +1018,22 @@ public class AccessLogValve extends ValveBase implements AccessLog {
pathname = dir.getAbsolutePath() + File.separator + prefix
+ suffix;
}
- writer = new PrintWriter(new BufferedWriter(new FileWriter(
- pathname, true), 128000), false);
-
+ 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();
+ }
+ writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
+ new FileOutputStream(pathname, true), charset), 128000),
+ false);
+
currentLogFile = new File(pathname);
} catch (IOException e) {
writer = null;
diff --git a/java/org/apache/catalina/valves/LocalStrings.properties b/java/org/apache/catalina/valves/LocalStrings.properties
index a2b791ef7..751fa1280 100644
--- a/java/org/apache/catalina/valves/LocalStrings.properties
+++ b/java/org/apache/catalina/valves/LocalStrings.properties
@@ -26,6 +26,7 @@ accessLogValve.closeFail=Failed to close 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}]
+accessLogValve.unsupportedEncoding=Failed to set encoding to [{0}], will use the system default character set.
# Error report valve
errorReportValve.errorReport=Error report
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index e84024a77..29a9d6c95 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -62,6 +62,10 @@
Character set used to write the log file. An empty string means + to use the system default character set. Default value: use the + system default character set. +
+The locale used to format timestamps in the access log lines. Any timestamps configured using an -- 2.11.0