tomcat打印日志乱码_针对tomcat日志乱码问题
最近公司內(nèi)的研發(fā)反映tomcat的程序的日志出現(xiàn)亂碼情況,經(jīng)查看tomcat輸出日志文件的編碼格式如下:
$ file xx
xx: ISO-8859 text, with very long lines
經(jīng)查看系統(tǒng)的編碼為:
$ 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
原來問題出在這,經(jīng)查閱一些資料得知tomcat的編碼處理順序為:
因為file.encoding默認的字符集跟操作系統(tǒng)有關(guān),中文操作系統(tǒng)下面默認的字符集是GBK,如果流程定義的xml文件中用UTF-8,
則不能正確轉(zhuǎn)換,所以需要修改file.encoding的值為UTF-8
所以在tomcat的啟動腳本(start.sh)中加入如下參數(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
總結(jié)
以上是生活随笔為你收集整理的tomcat打印日志乱码_针对tomcat日志乱码问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: timeSetEvent、回调函数、CC
- 下一篇: 递归算法时间复杂度计算