Hi,
I am using spring Cloud with spring-boot-starter-log4j2 and looks like the automatic pattern that includes app name, span id and trace id is not set as the docs are saying.
It's a logback only feature I think (from Spring Boot, so nothing we can fix here anyway).
Maybe adding to the documentation will save others time to understand it. I finally found the comment in the source code and figured it out. Thanks anyway
Hi ezraroi,
How did you figure out to this problem with log4j2 ?
+1, how to make it working with log4j2?
@hsj1606 @sdiallo-talend I guess you have to do exactly what is here https://github.com/spring-cloud/spring-cloud-sleuth/blob/master/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/log/Slf4jSpanLogger.java but using https://logging.apache.org/log4j/2.x/manual/thread-context.html . In other words just write your own implementation of SpanLogger
I got it working by simply adding log pattern and log4j2 dependancy.
Log4j2:
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html#howto-configure-log4j-for-logging
Pattern in application.properties:
logging.pattern.console=[%X{X-B3-TraceId},%X{X-B3-SpanId},%X{X-B3-ParentSpanId},%X{X-Span-Export}]
Did anyone actually test this solution? From the boot docs they state that logging.pattern.console is logback specific...
Most helpful comment
I got it working by simply adding log pattern and log4j2 dependancy.
Log4j2:
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html#howto-configure-log4j-for-logging
Pattern in application.properties:
logging.pattern.console=[%X{X-B3-TraceId},%X{X-B3-SpanId},%X{X-B3-ParentSpanId},%X{X-Span-Export}]