Wednesday, October 21, 2009

Set Character Encoding to log4j's File Log

Working with east asian characters? Do you want log4j to print out utf-8 characters on your log file? Here is how:

When you're using a log4j.properties file:


log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.encoding=UTF-8

When youre using a log4j.xml file:

<appender name="R"
              class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File" value="info-log.log"/>
        <param name="Encoding" value="UTF-8"/>
        ...
        ...
</appender>
Enjoy!

2 comments:

  1. Neat! I'm sure I'm gonna need this someday... Keep posting! :D

    ReplyDelete
  2. Its not working properly.instead of 는못하는 사람이 it is adding 는못하는 사람이 to log file

    ReplyDelete