rgoers commented on code in PR #2419:
URL: https://github.com/apache/logging-log4j2/pull/2419#discussion_r1544596128


##########
log4j-api/src/main/java/org/apache/logging/log4j/ScopedContext.java:
##########
@@ -0,0 +1,558 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.function.Supplier;
+import org.apache.logging.log4j.internal.ScopedContextAnchor;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * Context that can be used for data to be logged in a block of code.
+ *
+ * While this is influenced by ScopedValues from Java 21 it does not share the 
same API. While it can perform a
+ * similar function as a set of ScopedValues it is really meant to allow a 
block of code to include a set of keys and
+ * values in all the log events within that block. The underlying 
implementation must provide support for
+ * logging the ScopedContext for that to happen.
+ *
+ * The ScopedContext will not be bound to the current thread until either a 
run or call method is invoked. The
+ * contexts are nested so creating and running or calling via a second 
ScopedContext will result in the first
+ * ScopedContext being hidden until the call is returned. Thus the values from 
the first ScopedContext need to
+ * be added to the second to be included.
+ *
+ * The ScopedContext can be passed to child threads by including the 
ExecutorService to be used to manage the
+ * run or call methods. The caller should interact with the ExecutorService as 
if they were submitting their
+ * run or call methods directly to it. The ScopedContext performs no error 
handling other than to ensure the
+ * ThreadContext and ScopedContext are cleaned up from the executed Thread.
+ *
+ * @since 2.24.0
+ */
+public class ScopedContext {

Review Comment:
   @ppkarwasz I have no plans to merge this PR without ScopedContext. I am 
quite sure I will use it in my environment far more frequently than I will ever 
use ResourceLogger. I can easily envision Service 1 creating a ScopedContext 
that gets propogated to Service 2, which then adds its own ScopedContext data. 
This would be extremely valuable in the logs.



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