-
Notifications
You must be signed in to change notification settings - Fork 1k
Open
Labels
bugSomething isn't workingSomething isn't workingcontribution welcomeRequest makes sense, maintainers probably won't have time, contribution would be welcomeRequest makes sense, maintainers probably won't have time, contribution would be welcome
Description
When the Log4j LogEvent context data contains non string values e.g string arrays or java maps, the resulting attributes are incorrect.
Create a class extending ObjectThreadContextMap and set it as the default using the log4j system property log4j2.threadContextMap
Add the following code:
public class MyObjectContextMap implements ReadOnlyThreadContextMap, ObjectThreadContextMap {
//Implementation methods
}
In the logging code add the following
MyObjectContextMap map = (MyObjectContextMap)ThreadContext.getThreadContextMap();
map.putValue("numbers", new String[]{"one", "two", "three"});
HashMap testmap = new HashMap();
testmap.put("fn", "firstname");
testmap.put("ln", "lastname");
testmap.put(age, 25);
map.put("testmap", testmap);
logger.log(Level.TRACE, "test message");
What did you expect to see?
I would expect that the nested value and the array value would be included in attributes properly.
What did you see instead?
I saw the .toString() representations of the array and map. So numbers showed as an attribute with value [Ljava.lang.String and testmap showed up as a single value with the map values as {fn=firstname, ln=lastname}.
What version are you using?
1.23.0-alpha
Log4j: 2.17.1
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingcontribution welcomeRequest makes sense, maintainers probably won't have time, contribution would be welcomeRequest makes sense, maintainers probably won't have time, contribution would be welcome