I'm using implementation("org.springframework.cloud:spring-cloud-starter-sleuth:3.1.1") Library to add trace ID and span ID into the Logs. The auto-generated logs do have both but when I try to add custom logs those don't have anything. Example:
- Auto-generated logs: INFO [sample-api,49466c36531753f8,49466c36531753f8] 46131 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
- Custom logs- INFO [sample-api,,] 46131 --- [atcher-worker-1] c.l.c.a.w.c.SampleController : 1f45520c-8cf4-448a-bf7e-c20bf3401c44 harmeet
As can be seen in the custom logs don’t include trace id and span id
I have tried changing the logging pattern and level as well:
logging:
level:
org.springframework.web: "info"
org.hibernate: "error"
pattern:
level: "%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]"
Library used for logging:
import org.slf4j.LoggerFactory