最近公司内的研发反映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