標籤:解決 app ace ogg linu include frame path version
最近在做架構遷移工作,將原有springmvc項目調整至springboot架構上,遷移完後,發現用springboot以jar包形式啟動正常,用tomcat去啟動時日誌亂碼,但是項目部署至Linux環境啟動也正常,以下是日誌亂碼代碼:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="org.springframework.web" level="INFO"/>
<logger name="org.springboot.sample" level="TRACE" />
<!-- 開發、測試環境 --><springProfile name="dev,test,devtest"> <logger name="org.springframework.web" level="INFO"/> <logger name="org.springboot.sample" level="INFO" /> <logger name="hwja.com" level="DEBUG" /></springProfile><!-- 生產環境 --><springProfile name="prod"> <logger name="org.springframework.web" level="ERROR"/> <logger name="org.springboot.sample" level="ERROR" /> <logger name="hwja.com" level="ERROR" /></springProfile>
</configuration>
下面我們來分析一下:
windows系統預設編碼GBK,而項目編碼統一為UTF-8,與springboot整合的logback日誌預設編碼也設定的是UTF-8,所以導致日誌輸出為亂碼,Linux下面全為UTF-8,所以正常,那麼如何解決呢,解決思路將springboot整合的logback日誌預設編碼去掉,讓它自動去讀作業系統的環境編碼,也就是預設的tomcat中的file.encoding的預設值,解決後的日誌代碼如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/spring.log}"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<!--注意此處刪除編碼方式,讓其讀作業系統預設編碼-->
如果仍然有問題,可以聯絡我QQ:604313052 WX:Ca604313052
windows下啟動tomcat,日誌亂碼問題,日誌架構springboot+logback