log4j2 integration doesn't work, "logging.pattern.level" syntax incorrect in TraceEnvironmentPostProcessor
See original GitHub issueDescription
traceId and spanId don’t appear in log when using log4j2, e.g.:
2021-08-12 12:54:14.737 INFO [hello-app,,] 106004 --- [nio-8080-exec-1] c.e.d.FooController : hello
Reproduce
- exclude
org.springframework.boot:spring-boot-starter-logging - include
org.springframework.boot:spring-boot-starter-log4j2,org.springframework.cloud:spring-cloud-starter-sleuthandio.zipkin.brave:brave-context-log4j2 - define bean of type
ScopeDecoratorwithThreadContextScopeDecorator.get()
Cause
The value for logging.pattern.level in TraceEnvironmentPostProcessor uses e.g. %X{traceId:-} but the syntax for an empty default value isn’t supported by log4j2. See Pattern Layout
Workaround
Override the property with e.g.:
logging.pattern.level=%5p [${spring.zipkin.service.name:${spring.application.name:}},%X{traceId},%X{spanId}]
i.e. no :-
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
26. Logging - Spring
Spring Boot uses Commons Logging for all internal logging but leaves the underlying log implementation open. Default configurations are provided for Java ...
Read more >log4j properties file not creating log file in spring boot
Following is a working example for log4j2 integration with Spring boot. Tried with Gradle build but can be used for maven build too....
Read more >Log4j 2 Layouts - Apache Logging Services
An Appender uses a Layout to format a LogEvent into a form that meets the needs of whatever will be consuming the log...
Read more >Log4j 2 Tutorial: Configuration Example for Logging in Java
That means, that by default, ERROR level logs and beyond will be only visible. Log messages with level INFO, DEBUG, TRACE will not...
Read more >How to use Log4j 2 with Spring Boot | CalliCoder
Learn how to integrate and configure Log4j 2 in Spring Boot applications with RollingFile, SMTP appenders, and Async Loggers.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Since manual work is required to add such support with Brave maybe it’s enough to document that the pattern must be changed? WDYT?
spring-boot-starter-parent 2.5.3 and spring-cloud.version 2020.0.3