question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

log4j2 integration doesn't work, "logging.pattern.level" syntax incorrect in TraceEnvironmentPostProcessor

See original GitHub issue

Description

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

  1. exclude org.springframework.boot:spring-boot-starter-logging
  2. include org.springframework.boot:spring-boot-starter-log4j2, org.springframework.cloud:spring-cloud-starter-sleuth and io.zipkin.brave:brave-context-log4j2
  3. define bean of type ScopeDecorator with ThreadContextScopeDecorator.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:closed
  • Created 2 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
marcingrzejszczakcommented, Aug 12, 2021

Since manual work is required to add such support with Brave maybe it’s enough to document that the pattern must be changed? WDYT?

1reaction
farnettocommented, Aug 12, 2021

spring-boot-starter-parent 2.5.3 and spring-cloud.version 2020.0.3

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found