Github user HeartSaVioR commented on a diff in the pull request:
https://github.com/apache/storm/pull/2475#discussion_r159863976
--- 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 --
I think letting users leave the log message with providing enough
information is most flexible way. `handleLog` is adding some context which some
users might not want and in some case could disturb parsing the message.
So the ideal approach from my side is publishing all the necessary context
to multi-lang running subprocess and let subprocess build the full message
(without context which log4j2 format provides), but it might bring some
backward incompatibility like I said, or even some overhead because it should
be passed to multilang and longer message should be passed to
ShellSpout/ShellBolt.
I'm OK to follow proposal provided by @hmcc, which may not require huge
change. ID of the originating tuple is not available (we're sending generated
new ID to multilang) so need to be added in some way though.
---