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

   Hello all,
   
   Thank you for providing detailed comments 
[here](https://github.com/apache/logging-log4j2/issues/1414#issuecomment-1748852847).
   
   The mechanism introduced in `SLF4J` 2.x with the `addKeyValue` method looks 
very promising, but I found a couple of issues preventing my team from fully 
utilizing it:
   
   1. Complex Objects Serialization: The current implementation relies on 
`String.valueOf(value)`, which is insufficient for handling complex objects, 
especially when structured logging is required.
   2. Performance: The serialization happens synchronously, which can degrade 
performance in high-performance systems where complex objects need to be logged 
frequently.
   
   I would like to request an enhancement in Log4j that allows users to set a 
custom serializer.
   In the current `Log4jEventBuilder#addKeyValue(String key, Object value)` 
implementation, complex objects are serialized using `String.valueOf()`, which 
lacks flexibility. My suggestion is to allow users to provide a custom 
serializer that can handle more complex serialization needs (e.g., converting 
objects to `JSON`).
   
   Current Implementation in Log4j:
   ```
   @Override
   public LoggingEventBuilder addKeyValue(final String key, final Object value) 
{
       if (keyValuePairs == null) {
           keyValuePairs = new HashMap<>();
       }
       keyValuePairs.put(key, String.valueOf(value));  // Uses 
String.valueOf(value)
       return this;
   }
   ```
   
   Additionally, I propose that the serialization of the value should happen 
asynchronously, offloading the potentially expensive serialization task to a 
separate thread. This will prevent blocking the thread that calls logging 
methods (such as `log.info()`), thus improving performance in high-throughput 
logging environments where structured logging is used extensively.
   
   Thank you for your consideration.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to