ramanathan1504 commented on issue #4166:
URL: 
https://github.com/apache/logging-log4j2/issues/4166#issuecomment-5030605779

   @ppkarwasz @vy
   
   ```java
   private static final String[] MDC_KEYS = {
               "userId", "transactionId", "userRole",
               "@timestamp", "message", "log.level" 
       };
   
       private static final Pattern PATTERN = 
Pattern.compile("^(?!@timestamp|message|log\\.logger|log\\.level|event\\.dataset|process\\.thread\\.name|process\\.thread\\.id|ecs\\.version).*$");
   
       private static final Set<String> EXCLUDED_KEYS = new 
HashSet<>(Arrays.asList(
               "@timestamp", "message", "log.logger", "log.level",
               "event.dataset", "process.thread.name", "process.thread.id", 
"ecs.version"
       ));
   
       @Benchmark
       public int testRegex() {
           int allowedCount = 0;
           for (String key : MDC_KEYS) {
               if (PATTERN.matcher(key).matches()) {
                   allowedCount++;
               }
           }
           return allowedCount;
       }
   
       @Benchmark
       public int testKeyExcludes() {
           int allowedCount = 0;
           for (String key : MDC_KEYS) {
               if (!EXCLUDED_KEYS.contains(key)) {
                   allowedCount++;
               }
           }
           return allowedCount;
       }
   ```
   
   #Result
   
   ```text
   Benchmark                               Mode  Cnt   Score   Error   Units
   MdcKeyFilterBenchmark.testKeyExcludes  thrpt    5  83.571 ± 6.988  ops/us
   MdcKeyFilterBenchmark.testRegex        thrpt    5   4.500 ± 0.073  ops/us
   
   


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