1、pom.xml加入log4j2,並同時把spring boot默認的logging去掉
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions><!-- 去掉默認配置 -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <!-- 引入log4j2依賴 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
</dependencies>
2、在src/main/resource下新建log4j2.xml,加入對應的配置(可參考http://blog.csdn.net/laozhou243/article/details/52426629)
3、在src/main/resource下新建application.properties文件(該文件用於修改spring boot的一些默認配置),配置log4j2.xml的配置
logging.config=classpath:log4j2.xml
4、添加Logger,用LoggerFactory,不用LogManager,Application是測試類
Logger logger = LoggerFactory.getLogger(Application.class);