首页 > 其他分享 >spring boot logback日志显示时间差8小时

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

时间:2023-09-06 12:22:47浏览次数:39  
标签:mm spring boot SSS yyyy ss HH logback

参考: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

 

标签:mm,spring,boot,SSS,yyyy,ss,HH,logback
From: https://www.cnblogs.com/gaoyanbing/p/17681999.html

相关文章

  • SpringBoot启动报数组下标越界
    问题描述:启动读取配置文件时报错关键字:ERRORorg.springframework.boot.SpringApplication-Applicationrunfailedjava.lang.ArrayIndexOutOfBoundsException:-1ConnectedtothetargetVM,address:'127.0.0.1:58753',transport:'socket'2023-09-0611:09......
  • Spring学习第一步
    @TOC<hrstyle="border:solid;width:100px;height:1px;"color=#000000size=1">1、Spring概述1.1简介Spring:春天--->给软件行业带来了春天2002年,RodJahnson首次推出了Spring框架雏形interface21框架。2004年3月24日,Spring框架以interface21框架为基础,经过重新设计,发布了1......
  • SpringBoot整合Redis
    SpringBoot整合Redis整合springcache导入依赖<!--引入redis--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>......
  • Spring Boot中自动装配机制的原理
    SpringBoot中自动装配机制的原理1.自动装配,简单来说就是自动把第三方组件的Bean装载到SpringIOC容器里面,不需要开发人员再去写Bean的装配配置,2.在SpringBoot应用里面,只需要在启动类加上@SpringBootApplication注解就可以实现自动装配。3.@SpringBootApplication是一个复合注......
  • 007-SpringBoot+Mybatis+Sqlite框架搭建
    1,配置文件(application.yaml)server:port:6695spring:datasource:url:jdbc:sqlite:D:/examtolearn.dbusername:password:driver-class-name:org.sqlite.JDBCmybatis:mapper-locations:classpath:mapper/*.xmlconfiguration:log-......
  • 聊聊如何玩转spring-boot-admin
    前言1、何为spring-boot-admin?SpringBootAdmin是一个监控工具,旨在以良好且易于访问的方式可视化SpringBootActuators提供的信息快速开始如何搭建spring-boot-admin-server1、在服务端项目的POM引入相应的GAV<dependency><groupId>de.codecentric<......
  • springCloud学习笔记整理
    springCloud学习笔记整理1.分布式分布式的概念:根据业务功能对系统做拆分,每个业务功能模块作为独立项目开发,称为一个服务。分布式架构的优缺点:优点:降低服务耦合有利于服务升级和拓展缺点:服务调用关系错综复杂2.微服务微服务的上述特性其实是在给分布式架构制......
  • Spring源码分析(十二)ApplicationContext详解(中)
    上篇文章已经对ApplicationContext的一部分内容做了介绍,ApplicationContext主要具有以下几个核心功能:国际化借助Environment接口,完成了对Spring运行环境的抽象,可以返回环境中的属性,并能出现占位符借助于Resource系列接口,完成对底层资源的访问和加载接触了ApplicationEventPublishe......
  • 解决代码使用CompletableFuture做异步时spring-cloud-starter-sleuth的日志追踪号为空
    产生问题原因就是异步调用,导致spanId和traceId丢失了@Async注解的异步调用是没问题的前提使用spring-cloud-starter-sleuthjar包版本2.2.8.RELEASE关于追踪号的xml配置为<pattern>%yellow(%date{yyyy-MM-ddHH:mm:ss.SSS})[%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-B......
  • Springboot+Quartz+Dynamic-datasource
    在使用dynamic-datasource多数据源切换场景下,实现Quartz任务持久化配置和API动态调度1.pom依赖暂未找到版本对应关系,若有版本不一致异常,请自行尝试升降版本。<dependencies><!--动态数据源--><dependency><groupId>com.baomidou</groupI......