Skip to content

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

@farnetto

Description

@farnetto

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions