You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "lukasalexanderweber (via GitHub)" <gi...@apache.org> on 2024/04/03 19:55:36 UTC

[I] ContextDataInjector ignores custom ContextDataProvider (logging-log4j2)

lukasalexanderweber opened a new issue, #2331:
URL: https://github.com/apache/logging-log4j2/issues/2331

   ## Description
   
   Per documentation I should be able to create a [custom ContextDataProvider](https://logging.apache.org/log4j/2.x/manual/extending.html#ContextDataProvider). However, when following the documented steps, the context is not resolved. This is also reported [here](https://stackoverflow.com/questions/77455596/define-contextdataprovider-in-log4j2-at-creation-time-of-logger).
   
   I created a [minimal reproducible example](https://github.com/lukasalexanderweber/ContextDataProviderMRE/) where I followed the steps described in the docs:
   
   1. Custom implementations should implement the `org.apache.logging.log4j.core.util.ContextDataProvider` interface ([MyContextDataProvider](https://github.com/lukasalexanderweber/ContextDataProviderMRE/blob/main/src/main/java/custom/context/data/provider/MyContextDataProvider.java))
   2. and declare it as a service by defining the implementation class in a file named `META-INF/services/org.apache.logging.log4j.core.util.ContextDataProvider` ([org.apache.logging.log4j.core.util.ContextDataProvider](https://github.com/lukasalexanderweber/ContextDataProviderMRE/blob/main/src/main/resources/META-INF/services/org.apache.logging.log4j.core.util.ContextDataProvider))
   
   I created a [unit test](https://github.com/lukasalexanderweber/ContextDataProviderMRE/blob/main/src/test/java/custom/context/data/provider/MyContextDataProviderTest.java) with a [log4j2-test.properties setup](https://github.com/lukasalexanderweber/ContextDataProviderMRE/blob/main/src/test/resources/log4j2-test.properties) and expect for the path `src/test/logs/${ctx:tenant}` that the tenant is resolved by `MyContextDataProvider`. However, an error is printed that the file with the unresolved tenant cannot be created. It works as expected when the tenant is set via `ThreadContext.put("tenant", "tenant1");`
   
   ## Configuration
   
   **Version:** 2.23.0
   
   **Operating system:** Windows 10
   
   **JDK:** Corretto-17.0.8.8.1
   
   ## Logs
   
   ```
   2024-03-01T08:40:19.499742800Z main ERROR Unable to create file src/test/logs/${ctx:tenant}/logs.log java.io.IOException: Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch
   	at java.base/java.io.WinNTFileSystem.canonicalize0(Native Method)
   	at java.base/java.io.WinNTFileSystem.canonicalize(WinNTFileSystem.java:462)
   	at java.base/java.io.File.getCanonicalPath(File.java:626)
   	at java.base/java.io.File.getCanonicalFile(File.java:651)
   	at org.apache.logging.log4j.core.util.FileUtils.makeParentDirs(FileUtils.java:141)
   	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory.createManager(RollingFileManager.java:863)
   
   ```
   
   ## Reproduction
   
   see [ContextDataProviderMRE](https://github.com/lukasalexanderweber/ContextDataProviderMRE)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ContextDataInjector ignores custom ContextDataProvider (logging-log4j2)

Posted by "rgoers (via GitHub)" <gi...@apache.org>.
rgoers closed issue #2331: ContextDataInjector ignores custom ContextDataProvider
URL: https://github.com/apache/logging-log4j2/issues/2331


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ContextDataInjector ignores custom ContextDataProvider (logging-log4j2)

Posted by "lukasalexanderweber (via GitHub)" <gi...@apache.org>.
lukasalexanderweber commented on issue #2331:
URL: https://github.com/apache/logging-log4j2/issues/2331#issuecomment-2098222865

   @rgoers the PR you mentioned is merged, is this issue resolved?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ContextDataInjector ignores custom ContextDataProvider (logging-log4j2)

Posted by "lukasalexanderweber (via GitHub)" <gi...@apache.org>.
lukasalexanderweber commented on issue #2331:
URL: https://github.com/apache/logging-log4j2/issues/2331#issuecomment-2664744425

   Hello @ppkarwasz, I've[ just updated the MRE to `2.24.2`](https://github.com/lukasalexanderweber/ContextDataProviderMRE/tree/24) and it's still not able to create the directory `/target/logs/${ctx:tenant}`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ContextDataInjector ignores custom ContextDataProvider (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on issue #2331:
URL: https://github.com/apache/logging-log4j2/issues/2331#issuecomment-2293096136

   We postponed the merge of #2438 until 2.25.0.
   However I have backported the part that fixes this issue in #2846. It is planned to be released in 2.24.0.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ContextDataInjector ignores custom ContextDataProvider (logging-log4j2)

Posted by "rgoers (via GitHub)" <gi...@apache.org>.
rgoers commented on issue #2331:
URL: https://github.com/apache/logging-log4j2/issues/2331#issuecomment-2028149070

   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](https://logging.apache.org/log4j/2.x/manual/extending.html) 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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ContextDataInjector ignores custom ContextDataProvider (logging-log4j2)

Posted by "rgoers (via GitHub)" <gi...@apache.org>.
rgoers commented on issue #2331:
URL: https://github.com/apache/logging-log4j2/issues/2331#issuecomment-2098600215

   We have not released 2.24.0 yet. You can try with the latest SNAPSHOT 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ContextDataInjector ignores custom ContextDataProvider (logging-log4j2)

Posted by "lukasalexanderweber (via GitHub)" <gi...@apache.org>.
lukasalexanderweber commented on issue #2331:
URL: https://github.com/apache/logging-log4j2/issues/2331#issuecomment-2036387491

   great! Till now we used [ContextDataInjector](https://logging.apache.org/log4j/2.x/javadoc/log4j-core/org/apache/logging/log4j/core/ContextDataInjector.html) 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. 
   
   > NOTE: It is no longer recommended that custom implementations of this interface be provided as it is difficult to do. Instead, provide a custom ContextDataProvider.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ContextDataInjector ignores custom ContextDataProvider (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz closed issue #2331: ContextDataInjector ignores custom ContextDataProvider
URL: https://github.com/apache/logging-log4j2/issues/2331


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ContextDataInjector ignores custom ContextDataProvider (logging-log4j2)

Posted by "rgoers (via GitHub)" <gi...@apache.org>.
rgoers commented on issue #2331:
URL: https://github.com/apache/logging-log4j2/issues/2331#issuecomment-2035462644

   Well, I am going to reopen this as PR https://github.com/apache/logging-log4j2/pull/2438 actually fixes this.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] ContextDataInjector ignores custom ContextDataProvider (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on issue #2331:
URL: https://github.com/apache/logging-log4j2/issues/2331#issuecomment-1972922217

   Thank you for the report.
   
   Technically [`ContextDataInjector#injectContextData`](https://logging.apache.org/log4j/2.x/javadoc/log4j-core/org/apache/logging/log4j/core/ContextDataInjector.html#injectContextData(java.util.List,org.apache.logging.log4j.util.StringMap)) works correctly, so you'll see your "context" in your logs, but the [`ContextDataInjector#rawContextData`](https://logging.apache.org/log4j/2.x/javadoc/log4j-core/org/apache/logging/log4j/core/ContextDataInjector.html#rawContextData()) method doesn't, so you don't see it in the context lookup. We'll look into that.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org