tomcat打印日志乱码_针对tomcat日志乱码问题

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值