问题描述

tomcat启动的时候控制台和日志会乱码,虽然不影响啥但是看着就很恶心

控制台信息

10-Jul-2020 17:37:30.387 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server.鏈嶅姟鍣ㄧ増鏈�: Apache Tomcat/9.0.24
10-Jul-2020 17:37:30.389 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server.鏋勫缓: Aug 14 2019 21:16:42 UTC
10-Jul-2020 17:37:30.389 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.24.0
10-Jul-2020 17:37:30.389 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows

log日志信息

10-Jul-2020 17:37:30.405 淇℃伅 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
10-Jul-2020 17:37:30.408 淇℃伅 [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1c 28 May 2019]
10-Jul-2020 17:37:30.574 淇℃伅 [main] org.apache.coyote.AbstractProtocol.init 鍒濆鍖栧崗璁鐞嗗櫒 ["http-nio-8080"]
10-Jul-2020 17:37:30.591 淇℃伅 [main] org.apache.coyote.AbstractProtocol.init 鍒濆鍖栧崗璁鐞嗗櫒 ["ajp-nio-8009"]
10-Jul-2020 17:37:30.593 淇℃伅 [main] org.apache.catalina.startup.Catalina.load 鏈嶅姟鍣ㄥ湪[362]姣鍐呭垵濮嬪寲
10-Jul-2020 17:37:30.613 淇℃伅 [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
10-Jul-2020 17:37:30.613 淇℃伅 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.24]
10-Jul-2020 17:37:30.621 淇℃伅 [main] org.apache.coyote.AbstractProtocol.start 寮�濮嬪崗璁鐞嗗彞鏌刐"http-nio-8080"]
10-Jul-2020 17:37:30.628 淇℃伅 [main] org.apache.coyote.AbstractProtocol.start 寮�濮嬪崗璁鐞嗗彞鏌刐"ajp-nio-8009"]
10-Jul-2020 17:37:30.630 淇℃伅 [main] org.apache.catalina.startup.Catalina.start Server startup in [36] milliseconds

按照网上大部分的做法,要么控制台乱码解决了,日志文件乱码,要么日志文件解决了,控制台又乱码了。


解决方案

不说废话,直接给解决方案

编辑Tomcat的安装目录下的conf文件夹里的logging.properties

将里面所有的encoding的值改为GBK

如下

1catalina.org.apache.juli.AsyncFileHandler.level = FINE
1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.
1catalina.org.apache.juli.AsyncFileHandler.maxDays = 90

#改这里
1catalina.org.apache.juli.AsyncFileHandler.encoding = GBK

2localhost.org.apache.juli.AsyncFileHandler.level = FINE
2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.
2localhost.org.apache.juli.AsyncFileHandler.maxDays = 90

#改这里
2localhost.org.apache.juli.AsyncFileHandler.encoding = GBK

3manager.org.apache.juli.AsyncFileHandler.level = FINE
3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.AsyncFileHandler.prefix = manager.
3manager.org.apache.juli.AsyncFileHandler.maxDays = 90

#改这里
3manager.org.apache.juli.AsyncFileHandler.encoding = GBK

4host-manager.org.apache.juli.AsyncFileHandler.level = FINE
4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager.
4host-manager.org.apache.juli.AsyncFileHandler.maxDays = 90

#改这里
4host-manager.org.apache.juli.AsyncFileHandler.encoding = GBK

java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter

#改这里
java.util.logging.ConsoleHandler.encoding = GBK

重启IDEA和Tomcat,问题解决

亲测可用解决IDEA下serve output和log的乱码问题

文章目录