最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

spring boot - What is the simplest way to add corellationId to logging.pattern.console? - Stack Overflow

programmeradmin0浏览0评论

Initially I had such logging configuration in my spring boot 3.4 app:

logging:
  ...
  pattern:   
    file: "%d [%thread] %-5level %-50logger{40}- %n"
    console: "%d [%thread]%-5level %-50logger{40}- %n"

Then I've added tracing and trace/spanId was not added auomatically to my pattern so I've added:

  pattern:
    correlation: "[${spring.application.name:},%X{traceId:-},%X{spanId:-}]"
    file: "%d [%thread]${logging.pattern.correlation} %-5level %-50logger{40} - %n"
    console: "%d [%thread]${logging.pattern.correlation} %-5level %-50logger{40} %n"

Is there way to do it in a simpler way without explicit link to logging.pattern.correlation ?

is there smth like %thread for corellation ?

Initially I had such logging configuration in my spring boot 3.4 app:

logging:
  ...
  pattern:   
    file: "%d [%thread] %-5level %-50logger{40}- %n"
    console: "%d [%thread]%-5level %-50logger{40}- %n"

Then I've added tracing and trace/spanId was not added auomatically to my pattern so I've added:

  pattern:
    correlation: "[${spring.application.name:},%X{traceId:-},%X{spanId:-}]"
    file: "%d [%thread]${logging.pattern.correlation} %-5level %-50logger{40} - %n"
    console: "%d [%thread]${logging.pattern.correlation} %-5level %-50logger{40} %n"

Is there way to do it in a simpler way without explicit link to logging.pattern.correlation ?

is there smth like %thread for corellation ?

Share Improve this question asked Mar 12 at 7:48 gstackoverflowgstackoverflow 36.6k138 gold badges419 silver badges785 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The simplest way is doing nothing, this works out of the box and logs contain the correlation IDs. Iy you override the pattern and you don't use logging.pattern.correlation in it, it will bot be there (you are explicitly asking for not to be there). See the docs: https://docs.spring.io/spring-boot/reference/actuator/tracing.html#actuator.micrometer-tracing.logging

发布评论

评论列表(0)

  1. 暂无评论