ASF Bugzilla – Attachment 27278 Details for
Bug 46252
Tomcat access log doesn't support Unicode
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
2011-07-11_tc6_bug46252.patch
2011-07-11_tc6_bug46252.patch (text/plain), 4.68 KB, created by
Konstantin Kolinko
on 2011-07-11 16:01:05 UTC
(
hide
)
Description:
2011-07-11_tc6_bug46252.patch
Filename:
MIME Type:
Creator:
Konstantin Kolinko
Created:
2011-07-11 16:01:05 UTC
Size:
4.68 KB
patch
obsolete
>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 <code>null</code>, the >+ * system default character set will be used. An empty string will be >+ * treated as <code>null</code> 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 <code>null</code> 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).</p> > </attribute> > >+ <attribute name="encoding" required="false"> >+ <p>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. >+ </p> >+ </attribute> >+ > <attribute name="pattern" required="false"> > <p>A formatting layout identifying the various information fields > from the request and response to be logged, or the word
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 46252
:
27278
|
27279
|
27280