### 66.2. 配置Log4j Spring Boot也支持[Log4j](http://logging.apache.org/log4j/1.2)或[Log4j 2](http://logging.apache.org/log4j/2.x)作为日志配置,但只有在它们中的某个在classpath下存在的情况。如果你正在使用starter poms进行依赖装配,这意味着你需要排除Logback,然后包含你选择的Log4j版本。如果你不使用starter poms,那除了你选择的Log4j版本外还要提供commons-logging(至少)。 最简单的方式可能就是通过starter poms,尽管它需要排除一些依赖,比如,在Maven中: ```xml org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-logging org.springframework.boot spring-boot-starter-log4j ``` 想要使用Log4j 2,只需要依赖`spring-boot-starter-log4j2`而不是`spring-boot-starter-log4j`。 **注**:使用Log4j各版本的starters都会收集好依赖以满足common logging的要求(比如,Tomcat中使用`java.util.logging`,但使用Log4j或 Log4j 2作为输出)。具体查看Actuator Log4j或Log4j 2的示例,了解如何将它用于实战。