spring boot logback日志显示时间差8小时
参考: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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了