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>
- <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);