I found SMTPAppender doesn't send japanese message correctly
and FileAppender always uses the default encoding.
I could solve the problems by writing subclasses
but I think it's better SMTPAppender and FileAppender would be improved for them.
I modified SMTPAppender.java and FileAppender.java of log4j-1.1.3 then tested.
It worked fine.

Could anybody please merge the changes to the original source?

If you have any questions, please let me know.
Thanks very much.


* Problem

SMTPAppender

The mail I received has
Content-Type: text/plain
though the body contains like ???
because the japanese string isn't converted correctly.


FileAppender

I would like to write logs in utf-8
but FileAppender always uses the default encoding..
and there is no way to specify the encoding.


* Modification

SMTPAppender

Add the feature to specify a charset.


FileAppender

Add the feature to specify an encoding.


* Source code modification

org/apache/log4j/net/SMTPAppender.java

54a55
>   private String charset;
339c340,343
<       part.setContent(sbuf.toString(), layout.getContentType());
---
>       part.setContent(sbuf.toString(),
>                     charset == null ?
>                       layout.getContentType() :
>                       layout.getContentType() + ";charset=" + charset);
513a518,527
>   }
>
>   public
>   void setCharset(String charset) {
>     this.charset = charset;
>   }
>
>   public
>   String getCharset() {
>     return charset;


org/apache/log4j/FileAppender.java

14a15
> import java.io.FileOutputStream;
84a86,87
>   private String encoding = null;
>
227a231,239
>   public
>   void setEncoding(String encoding) {
>     this.encoding = encoding;
>   }
>
>   public
>   String getEncoding() {
>     return encoding;
>   }
284c296,300
<     this.setQWForFiles(new FileWriter(fileName, append));
---
>     this.setQWForFiles(encoding == null ?
>                       new FileWriter(fileName, append) :
>                       new OutputStreamWriter(
>                               new FileOutputStream(fileName, append),
>                               encoding));


* Test

I tested modified code using a XML configuration file.
I put
 <param name="Encoding" value="utf-8"/>
for org.apache.log4j.FileAppender,
org.apache.log4j.RollingFileAppender
org.apache.log4j.DailyRollingFileAppender
and
 <param name="Charset" value="iso-2022-jp"/>
for org.apache.log4j.net.SMTPAppender.
I ran the test program with javamail-1.2 and jaf-1.0.1.
It worked file.


Naozo



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to