> 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/75.-embedded-web-servers/75.9-configure-access-logging.md).

# 75.9 配置访问日志

通过相应的命令空间可以为Tomcat、Undertow和Jetty配置访问日志，例如下面是为Tomcat配置的一个[自定义模式](https://tomcat.apache.org/tomcat-8.5-doc/config/valve.html#Access_Logging)的访问日志：

```
server.tomcat.basedir=my-tomcat
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%t %a "%r" %s (%D ms)
```

**注** 日志默认路径为Tomcat基础路径下的`logs`目录，该dir默认是个临时目录，所以你可能想改变Tomcat的base目录或为日志指定绝对路径。上述示例中，你可以在相对于应用工作目录的`my-tomcat/logs`访问到日志。

Undertow的访问日志配置方式类似：

```
server.undertow.accesslog.enabled=true
server.undertow.accesslog.pattern=%t %a "%r" %s (%D ms)
```

日志存储在相对于应用工作目录的`logs`目录下，可以通过`server.undertow.accesslog.directory`属性自定义。

最后，Jetty的访问日志也可以这样配置：

```
server.jetty.accesslog.enabled=true
server.jetty.accesslog.filename=/var/log/jetty-access.log
```

默认地，日志会被重定向到`System.err`。更多细节，请查看[Jetty文档](https://www.eclipse.org/jetty/documentation/9.4.x/configuring-jetty-request-logs.html)。
