You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2019/06/25 11:02:58 UTC

[GitHub] [pulsar] Jennifer88huang commented on a change in pull request #4587: [Doc] Add two methods (log topic & CLI) for debugging functions

Jennifer88huang commented on a change in pull request #4587: [Doc] Add two methods (log topic & CLI) for debugging functions
URL: https://github.com/apache/pulsar/pull/4587#discussion_r297123869
 
 

 ##########
 File path: site2/docs/functions-debugging.md
 ##########
 @@ -124,3 +130,322 @@ To use localrun like above programmatically please addd the following dependency
 For complete code samples, see [here](https://github.com/jerrypeng/pulsar-functions-demos/tree/master/debugging)
 
 In the future, debugging with localrun mode for Pulsar Functions written in other languages will be supported.
+
+## Use log topic
+
+The Pulsar Functions allows you to output the log information defined in functions to a specified log topic. Consumers can be configured to consume messages from a specified log topic to check the log information.
+
+![Pulsar Functions core programming model](assets/pulsar-functions-overview.png)
+
+**Example** 
+
+```text
+import org.apache.pulsar.functions.api.Context;
+import org.apache.pulsar.functions.api.Function;
+import org.slf4j.Logger;
+
+public class LoggingFunction implements Function<String, Void> {
+    @Override
+    public void apply(String input, Context context) {
+        Logger LOG = context.getLogger();
+        String messageId = new String(context.getMessageId());
+
+        if (input.contains("danger")) {
+            LOG.warn("A warning was received in message {}", messageId);
+        } else {
+            LOG.info("Message {} received\nContent: {}", messageId, input);
+        }
+
+        return null;
+    }
+}
+```
+
+As shown in the example below, you can get the logger via `context.getLogger()` and assign the logger to the `LOG` variable of `slf4j`, so you can define your desired log information in a function using the `LOG` variable. You also need to specify the topic to which the log information is produced.
 
 Review comment:
   below or above?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services