最近公司內的研發反映tomcat的程序的日誌出現亂碼情況,經查看tomcat輸出日誌文件的編碼格式如下:
$ file xx
xx: ISO-8859 text, with very long lines
經查看系統的編碼爲:
$ env | grep LANG
LANG=zh_CN.UTF-8
然後查看tomcat的配置文件:server.xml:
URIEncoding="utf-8" useBodyEncodingForURI="true"
查看這些沒問題,於是查看java進程的信息:
$ jinfo 15178 | grep file
Attaching to process ID 15178, please wait...
Debugger attached successfully.
Server compiler detected.
file.encoding.pkg = sun.io
file.separator = /
file.encoding = GBK
原來問題出在這,經查閱一些資料得知tomcat的編碼處理順序爲:
因爲file.encoding默認的字符集跟操作系統有關,中文操作系統下面默認的字符集是GBK,如果流程定義的xml文件中用UTF-8,
則不能正確轉換,所以需要修改file.encoding的值爲UTF-8
所以在tomcat的啓動腳本(start.sh)中加入如下參數-Dfile.encoding="UTF-8":export JAVA_OPTS=“ xxxxxxxxxx -Dfile.encoding="UTF-8" ”
重啓tomcat ,查看日誌中文不亂碼。該問題即解決。
查看進程信息:
$ jinfo 15178 | grep file
Attaching to process ID 15178, please wait...
Debugger attached successfully.
Server compiler detected.
java.util.logging.config.file =
file.encoding.pkg = sun.io
file.separator = /
file.encoding = UTF-8