dfa1 edited a comment on pull request #770:
URL: https://github.com/apache/logging-log4j2/pull/770#issuecomment-1072958711


   @rgoers yes, of course :-)  Let me try to explain clearly: in 
https://www.six-group.com/ there is an internal requirement to use a structured 
logging format (called unified log event) for all our applications. This format 
is quite rich and detailed: there are predefined events for auditing, security 
incidents and so on. 
   
   The initial implement was simply `JsonLayout` + fluent bit configuration 
(hundreds of lines of configuration): but that is not enough to express certain 
combination of logs (and quite complex to understand and hard to test).
   
   Then, after some struggling with fluent bit, I tried to write a custom 
plugin in log4j2 to have a `UnifiedLogEventLayout`. The experiment was 
successful : now it is possible to unit test all the possible events and I must 
say was also a learning experience (i.e. log4j plugins are awesome!). 
   
   And here the main point: I'm using custom SLF4J `Marker` instances to pass 
extra information like structured arg or predefined events. I don't expect to 
create thousands of markers per second, but usually we create few per day per 
application node (i.e. I'm not worried about performance at all).
   
   Example:
   ```java
   HealthCheck pojo = ...;
   LOGGER.info(StructuredArg.of(healthPojo), "health check status");
   ```
   
   `StructuredArg` implements `Marker` and `getName` yields always 
`STRUCTURED_ARG` but data is always different, so it cannot be cached by "name" 
(the default behaviour we have in log4j 2.17.x):
   
   
https://github.com/apache/logging-log4j2/blob/f72100df0decc9bda96b4d769822c4e48b2848fc/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLogger.java#L379-L388
   
   My first attempt to workaround the problem was to wrap my marker with 
`Log4jMarker` (to go via line 383). To implement this workaround I used a 
custom `org.slf4j.impl.StaticMarkerBinder`: problem is that now all application 
have 2 `StaticMakerBinders` and, since the order of Jars in the classpath 
matters, now we have a *second workaround* to manually specify the classpath 
for all applications (this is working but also very annoying!). 
   
   My second attempt was this one (in the hope that someone else finds this 
useful too!). I hope my use case is clear enough now /cc @carterkozak. 
   


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