apache / apache/logging-log4j2

Mixing `ContextDataProvider` and `ThreadContext`

Open
#2,099 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
3.6k
Forks
1.7k
Avg merge
21h 30m
Merged PRs (30d)
27

Description

## Description

Hi all, I just stumbled on an interesting behavior mixing `ContextDataProvider` and `ThreadContext`.

In short, my application is using a dependency that provides a custom `ContextDataProvider` through SPI, but in my application code I also use `ThreadContext`.

When bundling using the gradle shadowJar plugin, I didn't configured the plugin to merge the SPI files, thus only the custom `ContextDataProvider` was loaded in the uber JAR, and not the built-in `ThreadContextDataProvider`.

Although it makes sense from the `ServiceLoader` POV, I wonder if something can be done to make this behavior less subtle, some ideas:

* log4j2 could still mount the `ThreadContextDataProvider`, even though is not registered through SPI
* log4j2 could print a warning when using `ThreadContext` but no `ThreadContextDataProvider` was loaded
* Perhaps adding some documentation here helps as well https://logging.apache.org/log4j/2.x/manual/extending.html#custom-contextdataprovider , although for the final users that are mixing libraries, this might not be obvious anyway

## Configuration

**Version:** 2.22.0

**Operating system:** Linux

**JDK:** 21

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.