spring boot logback日志显示时间差8小时

发布时间 2023-09-06 12:19:00作者: GaoYanbing

参考:https://blog.csdn.net/u014453475/article/details/100579856

官方文档:

The second parameter specifies a timezone. For example, the '%date{HH:mm:ss.SSS, Australia/Perth} would print the time in the time zone of Perth, Australia, the world's most isolated city. Note that in the absence of the timezone parameter, the default timezone of the host Java platform is used. If the specified timezone identifier is unknown or misspelled, the GMT timezone is assumed as dictated by the TimeZone.getTimeZone(String) method specification.

意思是可以在yyyy-MM-dd HH:mm:ss.SSS后面加一个指定的时区,用逗号分隔开。如yyyy-MM-dd HH:mm:ss.SSS,CTT

1
2
<property name="CONSOLE_LOG_PATTERN"
          value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS})

 

 

1
2
<property name="CONSOLE_LOG_PATTERN"
          value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS,CTT})

CTT为上海时间

今天遇到如题的问题,各种搜索关键字都找不到我想要的,基本搜索到的都是mysql的jdbcurl后面加一个配置,我用的是sqlserver跟这个没有关系。

还有提到applicationContext里加上这句话的,我也试了没用

spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
期间还怀疑了logback版本、windows时间问题

------------------------------------------------------------------------------------------------------------

最后发现是logback的pattern导致的,官网有解释https://logback.qos.ch/manual/layouts.html

我是错在HH:mm:ss.SSS和HH:mm:ss,SSS。

我直接搜索yyyy,搜到第一段有了含逗号的那个patern就直接复制粘贴拿来用了,后面发现是logback配置文件问题一步一步细分发现是patern去查了官网才发现这个问题。

官方说: Given that the comma ',' character is interpreted as the parameter separator, the pattern HH:mm:ss,SSS will be interpreted as the pattern HM:mm:ss and the timezone SSS. If you wish to include a comma in your date pattern, then simply enclose the pattern between quotes. For example, %date{"HH:mm:ss,SSS"}.

在使用逗号时,会默认使用时区设置,坑了我一个下午。。。啊大家引以为戒,看文章仔细点
————————————————
版权声明:本文为CSDN博主「米酒一米九」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u014453475/article/details/100579856