windows下啟動tomcat,日誌亂碼問題,日誌架構springboot+logback

來源:互聯網
上載者:User

標籤:解決   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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.