In the new project, logback + slf4j is used to replace the original log4j + slf4j and run as a WebApplication in tomcat. It is found that all Chinese characters in the generated log file are garbled. The first solution is to set the encoding of the generated log file in logback. Two settings are found on the internet, but they do not work: 1. logback + slf4j is used to replace the original log4j + slf4j in the new project, and is used as a Web Appli
CatIon in
McRun at and find that all Chinese characters in the generated log file are garbled.
The first solution is to set the encoding of the generated log file in logback. Two settings are found on the Internet,But none of them work.:
1. Set ENcOding. Add a row in appender UTF-8 But an error is reported during startup, saying that the Encoding element cannot be recognized. Some people say that Encoding is no longer available in Versions later than 0.9.22. So we found the second method.
2. Set char in EncoderSet. Logback implements different Encoder in the Set, where LayoutWrapPingEncoder has a charset attribute, and someone mentioned that you can use charset to set the log file encoding. Modify the encoder attribute:
- <Encoder Class="Ch. qos. logback. core. encoder. LayoutWrappingEncoder">
- <Pattern>% D {yyyy-MM-DdHH: mm: ss. SSS }:% p [% c] [% t] % m % n Pattern>
- <Charset>UTF-8 Charset>
- Encoder>
However, the system prompts that pattern cannot be found at startup.
Therefore, both methods end with failure. It may be that I did not find the correct setting method. If you have successfully set the method, please share it.
Finally, you can change the encoding of logback by setting the JVM parameter during tomcat startup by using the encoding of the program running by default:
Open catalina. bat. In the first line of the code, that isSet CATALINA_OPTSPreviously, add a row:
Set JAVA_OPTS = % JAVA_OPTS %-DFile. Encoding = UTF-8
Restart tomcat to test the log file.