mynameborat commented on a change in pull request #1532:
URL: https://github.com/apache/samza/pull/1532#discussion_r715125388



##########
File path: 
samza-log4j2/src/main/java/org/apache/samza/logging/log4j2/StreamAppender.java
##########
@@ -152,18 +144,19 @@ public String getStreamName() {
   }
 
   /**
-   * Getter for the Config parameter.
+   * This should only be called after verifying that the {@link 
LoggingContextHolder} has the config.

Review comment:
       How do we ensure/enforce that?

##########
File path: 
samza-core/src/main/java/org/apache/samza/logging/LoggingContextHolder.java
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.samza.logging;
+
+import java.util.concurrent.atomic.AtomicReference;
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.samza.config.Config;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Holds information to be used by loggers. For example, some custom Samza 
log4j/log4j2 logging appenders need system
+ * configs for initialization, so this allows the configs to be passed to 
those appenders.
+ */
+public class LoggingContextHolder {
+  private static final Logger LOG = 
LoggerFactory.getLogger(LoggingContextHolder.class);
+  public static final LoggingContextHolder INSTANCE = new 
LoggingContextHolder();
+
+  private final AtomicReference<Config> config = new AtomicReference<>();
+
+  @VisibleForTesting
+  LoggingContextHolder() {
+  }

Review comment:
       If the intent is to only use the singleton, this pattern would still let 
classes under same package break the assumption. 
   
   Thoughts on having reset/clear method if you want to reuse the instance in 
the test? Not sure which option w/ tradeoffs fits better here.




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