下面的log4j.xml文件哪里设置的有问题?怎么IDEA log.info打出的中文是乱码?

2019-01-03 02:05发布

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" 
    "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd" >
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
         <param name="encoding" value="UTF-8" /> 
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss}--%p %l%n  %m%n"/>
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMax" value="ERROR" />
            <param name="LevelMin" value="DEBUG" />
            <param name="AcceptOnMatch" value="true" />
        </filter>
    </appender>

    <appender name="INFO" class="org.apache.log4j.DailyRollingFileAppender">
         <param name="encoding" value="UTF-8" />
        <param name="DatePattern" value="'_'yyyy-MM-dd'.log'"/>
         <param name="File" value="/log/xxx.log"/>
        <param name="Append" value="true"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss}--%p %l%n  %m%n"/>
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMax" value="INFO" />
            <param name="LevelMin" value="INFO" />
        </filter>
    </appender>
    
    <appender name="ERROR" class="org.apache.log4j.DailyRollingFileAppender">
         <param name="encoding" value="UTF-8" /> 
        <param name="DatePattern" value="'_'yyyy-MM-dd'.log'"/>
         <param name="File" value="/log/xxx.log"/>
        <param name="Append" value="true"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss}--%p %l%n  %m%n"/>
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMax" value="ERROR" />
            <param name="LevelMin" value="WARN" />
        </filter>
    </appender>
    
    <category name="org.springframework">
        <priority value="error" />
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="ERROR" />
    </category>
    
    <logger name="com.xxxx.data.mapper.xxxtMapper.updateCart">
        <level value="DEBUG"></level>
        <appender-ref ref="CONSOLE"/>
    </logger>
    
    <root>
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="INFO"/>
        <appender-ref ref="ERROR"/>
    </root>
</log4j:configuration>

1条回答
走好不送
2楼-- · 2019-01-03 02:50

idea的其他地方也需要设置utf-8

https://www.cnblogs.com/liaoyanglong/p/6639039.html 有的设置过tomcat,可以参考

查看更多
登录 后发表回答