Recently in the framework of the migration work, the original SPRINGMVC project to adjust to the Springboot architecture, after the migration, found to use the Springboot as a jar package boot normal, with Tomcat to start the log garbled, but the project deployment to the Linux environment boot is also normal, The following is the log garbled code:
<?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>
Let's take a look at the following:
Windows system default encoding GBK, and the project encoding unified UTF-8, and Springboot integrated logback log default encoding is also set UTF-8, so the log output is garbled, Linux under all UTF-8, so normal, then how to solve it, The solution will springboot integrated logback log default encoding, let it automatically read the operating system's environment code, also is the default Tomcat in the default value of File.encoding, the following log code to resolve:
<?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>
<!--note here to remove the encoding so that it reads the operating system by default--
If you still have a problem, you can contact me qq:604313052 wx:ca604313052
Windows launches Tomcat, log garbled issues, log schema Springboot+logback