【问题标题】:Jetty custom format log pattern in spring bootSpring Boot中的Jetty自定义格式日志模式
【发布时间】:2021-09-15 13:22:15
【问题描述】:

我们已将 Spring Boot 应用程序升级到 2.5,因此码头升级到 9.X

通过此次更新,server.jetty.accesslog.time-zone 不再是 application.property 中的有效条目。 我们需要 IST 中的时区,现在它是 GMT(默认)。知道如何将其设置为 IST。

升级前access.log 0:0:0:0:0:0:0:1 - - [20/Jul/2021:14:31:10 +0530] "POST /hotels/generate/partial/v1/refresh-hotel-tagging HTTP/1.1" 200 7 211960

我试过server.jetty.accesslog.custom-format= %{dd/MMM/yyyy:HH:mm:ss SSS}t 这给出了:[15/Sep/2021:13:11:47 942]

我们需要和以前一样的日志格式。

【问题讨论】:

    标签: spring-boot jetty embedded-jetty


    【解决方案1】:

    这在CustomRequestLog的javadoc中得到了回答

    https://javadoc.io/doc/org.eclipse.jetty/jetty-server/9.4.43.v20210629/org/eclipse/jetty/server/CustomRequestLog.html

    %{format|timeZone|locale}t
    
    The time that the request was received. Optional parameter in one of the following formats {format}, {format|timeZone} or {format|timeZone|locale}.  
       Format Parameter: (default format [18/Sep/2011:19:18:28 -0400] where the last number indicates the timezone offset from GMT.)
           Must be in a format supported by DateCache
      
       TimeZone Parameter:
           Default timeZone GMT
           Must be in a format supported by TimeZone.getTimeZone(String)
      
       Locale Parameter:
           Default locale Locale.getDefault()
           Must be in a format supported by Locale.forLanguageTag(String)
    

    因此,请以您的格式使用您想要的时区...

    %{dd/MMM/yyyy:HH:mm:ss SSS|IST}t
    

    您还可以选择指定区域设置(这对指定很有用。例如,如果您决定使用长名称来表示月份)

    使用 IST + 日语语言环境

    %{dd/MMM/yyyy:HH:mm:ss SSS|IST|ja}t
    

    【讨论】:

      猜你喜欢
      • 2015-03-11
      • 2022-10-20
      • 2015-08-14
      • 2019-12-05
      • 1970-01-01
      • 2016-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多