The encoding format of the log file to be output by log4j is the UTF-8.
Under normal circumstances, you only need to add the following code:
Log4j. appender. appender_name.encoding = UTF-8
However, this method becomes invalid when spring and log4j are integrated. The reason is not discussed in depth. It seems that spring has done some operations to block this configuration (if someone knows the reason, please leave a message. Thank you ).
The method I used is not to configure org. springframework. Web. util. log4jconfiglistener in Web. XML, and to initialize log4j configuration at Web startup.
The only problem is that webapprootkey can be configured through web. xml configuration, so that the relative path can be specified in log4j. properties.
The solution is to manually set: system. setproperty ("MyApp. root ", webrootpath), and then in log4j. $ {MyApp. root} references.
Log4j sets the log format to UTF-8