Idea输出日志乱码:Java web项目

一、问题描述

Java web项目,采用logback记录日志,使用tomcat做为启动容器,但是,当运行的时候,打印日志有很多中文乱码。网上参考了很多,但是总感觉没有详细明确的说法。

而且logback日志编码已经设置为UTF-8。

二、问题原因

Idea显示日志的编码,默认好像不是UTF-8,修改为UTF-8。同时Tomcat运行虚拟机VM的编码默认也不是UTF-8,所以也需要设置一下。

三、解决问题

1.设置IDEA显示编码为UTF-8

(1)Help-》Edit Custom VM Options...

(2)添加:-Dfile.encoding=UTF-8

2.设置tomcat运行编码是UTF-8

(1)打开配置

(2)添加:-Dfile.encoding=UTF-8


3.重启idea!【切记,一定要重启,否则不生效!】

4.重启之后结果

JDBC Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@13cf8d53] will not be managed by Spring
==>  Preparing: SELECT area_id, area_name, area_desc, priority, create_time, last_edit_time FROM tb_area ORDER BY priority DESC 
==> Parameters: 
<==    Columns: area_id, area_name, area_desc, priority, create_time, last_edit_time
<==        Row: 1, 南天门, null, 3, null, null
<==        Row: 2, 北天门, null, 2, null, null
<==      Total: 2

四、参考

1.https://www.cnblogs.com/Wicher-lsl/p/11317390.html

2.https://blog.csdn.net/c5113620/article/details/96285449

Guess you like

Origin blog.csdn.net/Romantic_321/article/details/110949077