需求:
1、springboot集成log4j
2、mybatis 打印 sql
实现:
pom.xml
1 <dependency> 2 <groupId>org.springframework.boot</groupId> 3 <artifactId>spring-boot-starter-log4j</artifactId> 4 <version>1.3.8.RELEASE</version> 5 </dependency>
log4j.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'> <appender name="console" class="org.apache.log4j.ConsoleAppender"> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{HH:mm:ss.SSS} [%t] %m%n" /> </layout> </appender> <logger name="org.springframework" additivity="false"> <level value ="ERROR"/> <appender-ref ref="console"/> </logger> <!-- 只打印sql --> <logger name="com.ebc.ghome.mapper"> <level value ="DEBUG"/> <appender-ref ref="console"/> </logger> <!-- DEBUG < INFO < WARN < ERROR 没有定义的logger将会使用root logger --> <root> <level value="INFO" /> <appender-ref ref="console" /> </root> </log4j:configuration>