Short story longer: while there is no public API for putting non-String values 
in the context map, the work done in that ticket and 
https://issues.apache.org/jira/browse/LOG4J2-1660 provide the hooks for 
installing a custom data structure for the context map. This data structure may 
support non-string values. I used these hooks to install a garbage free hybrid 
Object/primitive map in the trading system at work. Unfortunately this data 
structure  is not open source but it’s not rocket science either; it’s 
basically an extension of the array based string map in Log4j2 with a separate 
long[] array for the primitive values. You may need to provide a separate 
facade that the application can use instead of ThreadContext; this facade can 
provide methods like putLong(String, long) which are not available in the Log4j 
ThreadContext. 

(Shameless plug) Every java main() method deserves http://picocli.info

> On Nov 3, 2019, at 17:31, Remko Popma <remko.po...@gmail.com> wrote:
> 
> Volkan, 
> 
> See https://issues.apache.org/jira/browse/LOG4J2-1648 for more details. 
> 
> Remko.
> 
> (Shameless plug) Every java main() method deserves http://picocli.info
> 
>>> On Nov 3, 2019, at 13:57, Ralph Goers <ralph.go...@dslextreme.com> wrote:
>>> 
>> No. Our experience has shown that putting non-String values in ThreadLocals 
>> has to be done very carefully, so to make sure there aren’t any problems the 
>> ThreadContextMap only allows Strings.
>> 
>> Ralph
>> 
>>> On Nov 2, 2019, at 1:11 PM, Volkan Yazıcı <volkan.yaz...@gmail.com> wrote:
>>> 
>>> Hello,
>>> 
>>> LogEvent#getContextData() returns a ReadOnlyStringMap such that the
>>> provided get() and forEach() allow non-String values in the entries. That
>>> said, ReadOnlyStringMap#toMap() returns a Map<String, String>. Further,
>>> both ThreadContext.put() and ThreadContext.putAll() only allow String
>>> values. I am confused by this inconsistency. Is there a way to provide an
>>> MDC entry where the value is of a non-String type?
>>> 
>>> Best.
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
>> For additional commands, e-mail: log4j-user-h...@logging.apache.org
>> 

Reply via email to