Log4j sets the log format to UTF-8

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.