How do you tell Spring Boot to send the embedded Tomcat's access logs to stdout?

后端 未结 5 607
萌比男神i
萌比男神i 2020-12-28 08:47

In a standalone Spring Boot web application (executable jar), how do you tell Spring Boot that we want the embedded Tomcat instance\'s HTTP access logs to be sent to stdout?

5条回答
  •  醉梦人生
    2020-12-28 09:21

    Update 2019.02.11:

    These inks should be useful to map which properties you should set in application.properties:

    • tomcat
    • undertow

    @acohen answer is slightly correct. If you provide the empty double quotes it won't work. I will extend his answer because I think it's important for people who don't want to mess with adding dependencies or modifying code:

    config/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=
    
    

    Notes

    1. If you set file-date-format and suffix to be double quotes, you will have this error:
    java.io.FileNotFoundException: /dev/stdout"""" (Permission denied)
    
    
    1. If you don't include them in the config file, you will then be using defaults values and this error:
    java.io.FileNotFoundException: /dev/stdout.2019-02-07.log (Permission denied)
    
    1. If you leave them empty, then it will work.

提交回复
热议问题