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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://jack80342.gitbook.io/spring-boot/ix.-how-to-guides/75.-embedded-web-servers/75.9-configure-access-logging.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
