> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/ix.-how-to-guides/78.-logging.md).

# 78. 日志

除了通常由Spring框架的`spring-jcl`模块提供的Commons Logging API，Spring Boot没有强制的日志依赖关系。想要使用[Logback](http://logback.qos.ch/)，你需要包含它及`spring-jcl`。最简单的方式是通过依赖`spring-boot-starter-logging`的starter。对于一个web应用程序，你只需添加`spring-boot-starter-web`依赖，因为它依赖于logging starter。例如，使用Maven：

```markup
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
```

Spring Boot有一个`LoggingSystem`抽象，用于尝试通过classpath上下文配置日志系统。如果Logback可用，则首选它。如果你唯一需要做的就是设置不同日志级别，那可以通过在`application.properties`中使用`logging.level`前缀实现，比如：

```java
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
```

你也可以使用`logging.file`设置日志文件的位置（除控制台之外，默认会输出到控制台）。

想要对日志系统进行更细粒度的配置，你需要使用`LoggingSystem`支持的原生配置格式。默认情况下，Spring Boot从系统的默认位置加载原生配置（比如对于Logback为`classpath:logback.xml`），但你可以使用`logging.config`属性设置配置文件的位置。
