在独立的 Spring Boot Web 应用程序(可执行 jar)中,如何告诉 Spring Boot 我们希望将嵌入式 Tomcat 实例的 HTTP 访问日志发送到标准输出?
最佳答案
2019.02.11更新:
这些墨水应该有助于映射您应该在 application.properties
中设置的属性:
@acohen 回答稍微正确。如果您提供空的双引号,它将不起作用。我将扩展他的答案,因为我认为这对于不想添加依赖项或修改代码的人来说很重要:
配置/application.properties
# here we say that we want to enable accesslog
server.tomcat.accesslog.enabled=true
# it is important to understand what the options means:
# 'directory/prefix + suffix + file-date-format' will be
# the file that tomcat will try to open.
# /dev/stdout is standard output, so we want tomcat
# to write to that fd. Then, we need to play with
# directory, prefix, suffix and file-date-format to match our desired path.
server.tomcat.accesslog.directory=/dev
server.tomcat.accesslog.prefix=stdout
server.tomcat.accesslog.buffered=false
# Don't use empty double quotes, see below
server.tomcat.accesslog.suffix=
server.tomcat.accesslog.file-date-format=
注意事项
- 如果你设置
file-date-format
和suffix
为双引号,你会出现这个错误:
java.io.FileNotFoundException: /dev/stdout"""" (Permission denied)
- 如果您不将它们包含在配置文件中,您将使用默认值并出现此错误:
java.io.FileNotFoundException: /dev/stdout.2019-02-07.log (Permission denied)
- 如果您将它们留空,那么它将起作用。
关于tomcat - 你如何告诉 Spring Boot 将嵌入式 Tomcat 的访问日志发送到 stdout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36780680/