-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ContextDataInjector ignores custom ContextDataProvider #2331
Comments
Thank you for the report. Technically We'll look into that, although at first sight it might not be an easy improvement considering the performance restrictions. In the meantime, you could write a |
I am going to go one further. This is NOT a bug. The purpose of ContextDataProvider is to inject data into LogEvents. That is documented clearly in the Extending Log4j section of the manual. Now because the Context Lookup inspects data in the LogEvent when it is passed on it will work as you expect in that circumstance. But where no LogEvent exists it cannot possibly know where your extra data is located. Therefore I am closing this. |
Well, I am going to reopen this as PR #2438 actually fixes this. |
great! Till now we used ContextDataInjector to create the files and map the logs but we saw that it's recommended to switch to ContextDataProvider and then we were suprised that this functionality no longer works.
|
@rgoers the PR you mentioned is merged, is this issue resolved? |
We have not released 2.24.0 yet. You can try with the latest SNAPSHOT |
Description
Per documentation I should be able to create a custom ContextDataProvider. However, when following the documented steps, the context is not resolved. This is also reported here.
I created a minimal reproducible example where I followed the steps described in the docs:
org.apache.logging.log4j.core.util.ContextDataProvider
interface (MyContextDataProvider)META-INF/services/org.apache.logging.log4j.core.util.ContextDataProvider
(org.apache.logging.log4j.core.util.ContextDataProvider)I created a unit test with a log4j2-test.properties setup and expect for the path
src/test/logs/${ctx:tenant}
that the tenant is resolved byMyContextDataProvider
. However, an error is printed that the file with the unresolved tenant cannot be created. It works as expected when the tenant is set viaThreadContext.put("tenant", "tenant1");
Configuration
Version: 2.23.0
Operating system: Windows 10
JDK: Corretto-17.0.8.8.1
Logs
Reproduction
see ContextDataProviderMRE
The text was updated successfully, but these errors were encountered: