Bug 32074 - Layout.setContentType() needed!
Summary: Layout.setContentType() needed!
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Layout (show other bugs)
Version: 1.2
Hardware: All All
: P3 blocker
Target Milestone: ---
Assignee: log4j-dev
Depends on:
Reported: 2004-11-05 02:40 UTC by Bin Sun
Modified: 2005-08-02 12:20 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Bin Sun 2004-11-05 02:40:11 UTC
For Chinese developers, the log4j output often turns into chaos characters for 
Chinese text, eg. in email notifications.

After inspection, I found the problem is that "Layout.getContentType()" 
returns "text/plain" by default but there's no standard way to change it.

We need it to be "text/plain; charset=GBK", but we could only write our own 
Layout classes for each of the existing Layout sub-classes.

So Layout.setContentType() is urgently expected...
Comment 1 Curt Arnold 2004-11-05 23:49:05 UTC
Character encoding and content text are different concepts and it would be wrong to try to combine 
them.  Character encoding is appropriately handled at the appender, not the layout.  Layout's are 
always dealing with UTF-16 characters, the appenders are responsible for converting that to a byte 

WriterAppender derived appenders have an Encoding attribute that allows you to specify the encoding 
to be used.  Perhaps in your use case, that was not appropriately set or the appender in use does not 
appropriately control or report the encoding.

getContentType() is overriden in application specific layouts such as HTMLLayout (which returns text/
html) and XMLLayout (which I was surprised doesn't return text/xml).

Comment 2 Yoav Shapira 2005-08-02 20:20:44 UTC
I agree with Curt's comments, so I'm closing this issue.  setEncoding methods
are available and (in my experience with non-en_us locales) correctly implemented.