> 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/78.2-configure-log4j-for-logging/78.2.1-use-yaml-or-json-to-configure-log4j-2.md).

# 78.2.1 使用YAML或JSON配置Log4j2

除了它的默认XML配置格式，Log4j 2也支持YAML和JSON配置文件。想使用其他配置文件格式配置Log4j 2，你需要添加合适的依赖到classpath，并以匹配所选格式的方式命名配置文件：

| 格式   | 依赖                                                                                                       | 文件名                        |
| ---- | -------------------------------------------------------------------------------------------------------- | -------------------------- |
| YAML | `com.fasterxml.jackson.core:jackson-databind` `com.fasterxml.jackson.dataformat:jackson-dataformat-yaml` | `log4j2.yaml` `log4j2.yml` |
| JSON | `com.fasterxml.jackson.core:jackson-databind`                                                            | `log4j2.json` `log4j2.jsn` |
