Index: java/org/apache/catalina/valves/AccessLogValve.java
===================================================================
--- java/org/apache/catalina/valves/AccessLogValve.java (revision 1145184)
+++ java/org/apache/catalina/valves/AccessLogValve.java (working copy)
@@ -21,10 +21,13 @@
import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
+import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -47,6 +50,7 @@
import org.apache.coyote.RequestInfo;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.buf.B2CConverter;
/**
@@ -301,8 +305,15 @@
* Date format to place in log file name. Use at your own risk!
*/
protected String fileDateFormat = null;
-
+
/**
+ * Character set used by the log file. If it is 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.
*/
protected AccessLogElement[] logElements = null;
@@ -522,6 +533,29 @@
this.fileDateFormat = fileDateFormat;
}
+ /**
+ * 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
/**
@@ -730,9 +764,22 @@
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;
Index: java/org/apache/catalina/valves/LocalStrings.properties
===================================================================
--- java/org/apache/catalina/valves/LocalStrings.properties (revision 1145207)
+++ java/org/apache/catalina/valves/LocalStrings.properties (working copy)
@@ -30,6 +30,7 @@
# Access log valve
accessLogValve.alreadyStarted=Access Logger has already been started
accessLogValve.notStarted=Access Logger has not yet been started
+accessLogValve.unsupportedEncoding=Failed to set encoding to [{0}], will use the system default character set.
# Error report valve
errorReportValve.errorReport=Error report
Index: webapps/docs/config/valve.xml
===================================================================
--- webapps/docs/config/valve.xml (revision 1145184)
+++ webapps/docs/config/valve.xml (working copy)
@@ -103,6 +103,13 @@
(relative to $CATALINA_BASE).
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. +
+A formatting layout identifying the various information fields from the request and response to be logged, or the word