Log4j encoding problem
I have configured log4j SMTPAppender to send me error messages. It works, but I have a problem with non-ASCII data. The config uses HTMLLayout and their documentation states:
Attributes using this layout must be encoded in UTF-8 or UTF-16, or events containing non-ASCII characters may corrupt the log files.
My log files should contain UTF-8 data, but I cannot find where I can set the encoding for the appender. Here is the appender config:
<appender name="MAIL" class="org.apache.log4j.net.SMTPAppender">
<param name="BufferSize" value="25" />
<param name="SMTPHost" value="localhost" />
<param name="From" value="myapp@...com" />
<param name="Threshold" value="error" />
<param name="To" value="me@gmail.com" />
<param name="Subject" value="Error Occurred" />
<param name="LocationInfo" value="true"/>
<param name="encoding" value="UTF-8" />
<!-- <param name="Encoding" value="UTF-8"/> -->
<layout class="org.apache.log4j.HTMLLayout">
</layout>
</appender>
When the app starts up I got:
log4j: WARN No such property [encoding] in org.apache.log4j.net.SMTPAppender
+2
source to share
4 answers
According to the code of the latest SMTPAppender (1.2.15) , not only is there no setEncoding, but the encoding is not even mentioned there.
Do you really see problems with him? If so, why not inherit from SMTPAppender or provide your own implementation?
+1
source to share
The latest version (1.2.16) permits this.
subject: line 144
body: line 390
content type: line 394
It is also mentioned in the change log http://logging.apache.org/log4j/1.2/changes-report.html#a1.2.16
SMTPAppender does not properly encode subject or content containing non-ASCII characters. Fixes 44644.
+1
source to share