Skip to content

ContextDataInjector ignores custom ContextDataProvider #2331

Closed
@lukasalexanderweber

Description

@lukasalexanderweber

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:

  1. Custom implementations should implement the org.apache.logging.log4j.core.util.ContextDataProvider interface (MyContextDataProvider)
  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)

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

Metadata

Metadata

Assignees

Labels

bugIncorrect, unexpected, or unintended behavior of existing codewaiting-for-maintainer

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions