Github user hmcc commented on a diff in the pull request:
https://github.com/apache/storm/pull/2475#discussion_r159972449
--- Diff: storm-client/src/jvm/org/apache/storm/utils/ShellLogHandler.java
---
@@ -0,0 +1,113 @@
+/**
+ * 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.storm.utils;
+
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.storm.multilang.ShellMsg;
+import org.apache.storm.task.TopologyContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class ShellLogHandler {
+ public static final Logger LOG =
LoggerFactory.getLogger(ShellLogHandler.class);
+
+ public static final String ID = "id";
+ public static final String NAME = "name";
+ public static final String PARENT = "parent";
+ public static final String PID = "pid";
+ public static final String TASK = "task";
+
+ private ShellLogHandler() {
+ }
+
+ private static void putIfNotNull(String key, Object value) {
+ if (value != null) {
+ ThreadContext.put(key, value.toString());
+ }
+ }
+
+ /**
+ * Update the {@link ThreadContext} with information about the logged
+ * message, including the pid and task.
+ *
+ * @param shellMsg
+ * - the {@link ShellMsg} containing the ID.
+ * @param process
+ * - the current {@link ShellProcess}.
+ * @param context
+ * - the current {@link TopologyContext}.
+ */
+ private static void updateContext(ShellMsg shellMsg, ShellProcess
process, TopologyContext context) {
+ putIfNotNull(ID, shellMsg.getId());
+ // Calling this only once allows the same parent ID to be attached
to
+ // all log messages from a tuple tree
+ if (!ThreadContext.containsKey(PARENT)) {
+ putIfNotNull(PARENT, shellMsg.getId());
+ }
--- End diff --
Thanks, that sounds like a plan.
What do you prefer - close this and create a new PR, or leave this open,
revert the commit and add a new commit with those changes?
---