日志乱码
日志中有中文乱码,“中文” 日志打印出来是 “????”
要改成UTF-8编码。
00x0 日志编码
如果使用logback可以修改logback.xml文件配置
utf-8配置: logback.xml增加<charset>UTF-8</charset>
<appender name="FILE-AUDIT"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logdir}/log.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %class{1.} %M - %msg%xEx%n
</Pattern>
<charset>UTF-8</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${logdir}/log.%d{yy-MM-dd}.%i.log</fileNamePattern>
<maxHistory>60</maxHistory>
<totalSizeCap>10GB</totalSizeCap>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!--文件达到 最大128MB时会被压缩和切割 -->
<maxFileSize>128 MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
00x1 JVM进程的编码
java运行jar文件时指定编码:
java -Dfile.encoding=utf-8 -jar XXX.jar
00x2 数据传输过程编码
springboot全局字符编码设置:
spring.http.encoding.force=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
server.tomcat.uri-encoding=UTF-8