Github user hmcc commented on a diff in the pull request: https://github.com/apache/storm/pull/2475#discussion_r159850662 --- 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 for looking at this @revans2. Our use case is that we're running a Storm topology written in Python. As well as human-readable logs, the topology is also configured to write JSON logs which are sent to ELK. The parent ID is so that we can easily search for all log messages associated with a particular originating tuple. @HeartSaVioR has already made some comments on the [issue](https://issues.apache.org/jira/browse/STORM-2862), saying that modifying the format of the logs could break backwards compatibility. I've asked him about maybe making the logging output more configurable instead. If we went that way, we could drop the Python and Ruby part of this change, and handle that in our code. Sorry, I'd explained the missing JS support on the #2474 but it should have been here - the JS is written to support variable arguments (probably because of [STORM-2435](https://issues.apache.org/jira/browse/STORM-2435)). I can't see a way to support optional IDs without breaking the current behaviour.
---