log4j日志文件乱码问题的解决方法

时间:2021-08-26 21:17:36
  1. 解决方法:

    如果是log4j.properties为配置文件,比如:


    1. log4j.appender.A1=org.apache.log4j.RollingFileAppender  
    2. log4j.appender.A1.File=all.log  

    加入一行:

     

    1. log4j.appender.A1=org.apache.log4j.RollingFileAppender  
    2. log4j.appender.A1.Encoding=UTF-8  
    3. log4j.appender.A1.File=all.log 

     

     如果是log4j.xml为配置文件,比如:.

                        <appender name="A1" class="org.apache.log4j.RollingFileAppender">

                                 <param name="File" value="all.log" />

                                 ......
                        </appender>

              加入一行:

                       <appender name="A1" class="org.apache.log4j.RollingFileAppender">

                                 <param name="Encoding" value="UTF-8" />

                                 <param name="File" value="all.log" /> 
                                  ...... 
                       </appender>