This is an automated email from the ASF dual-hosted git repository.

penghui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new dcf8788  Add logger Function example for Go Function (#7176)
dcf8788 is described below

commit dcf87882685901fb0e4e5d8e54ca654abbffc767
Author: 冉小龙 <[email protected]>
AuthorDate: Sat Jun 6 12:59:25 2020 +0800

    Add logger Function example for Go Function (#7176)
    
    Add logger Function example for Go Function
---
 pulsar-function-go/examples/logFunc/logFunc.go | 40 ++++++++++++++++++++++++++
 site2/docs/functions-develop.md                |  9 +++---
 2 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/pulsar-function-go/examples/logFunc/logFunc.go 
b/pulsar-function-go/examples/logFunc/logFunc.go
new file mode 100644
index 0000000..941164b
--- /dev/null
+++ b/pulsar-function-go/examples/logFunc/logFunc.go
@@ -0,0 +1,40 @@
+//
+// 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 main
+
+import (
+       "context"
+
+       "github.com/apache/pulsar/pulsar-function-go/pf"
+
+       log "github.com/apache/pulsar/pulsar-function-go/logutil"
+)
+
+func loggerFunc(ctx context.Context, input []byte) {
+       if len(input) <= 100 {
+               log.Infof("This input has a length of: %d", len(input))
+       } else {
+               log.Warnf("This input is getting too long! It has {%d} 
characters", len(input))
+       }
+}
+
+func main() {
+       pf.Start(loggerFunc)
+}
diff --git a/site2/docs/functions-develop.md b/site2/docs/functions-develop.md
index 43f43a8..c2bdd16 100644
--- a/site2/docs/functions-develop.md
+++ b/site2/docs/functions-develop.md
@@ -644,10 +644,11 @@ The following Go Function example shows different log 
levels based on the functi
 
 ```
 import (
-       "context"
+    "context"
 
-       "github.com/apache/pulsar/pulsar-function-go/log"
-       "github.com/apache/pulsar/pulsar-function-go/pf"
+    "github.com/apache/pulsar/pulsar-function-go/pf"
+
+    log "github.com/apache/pulsar/pulsar-function-go/logutil"
 )
 
 func loggerFunc(ctx context.Context, input []byte) {
@@ -663,7 +664,7 @@ func main() {
 }
 ```
 
-When you use `logTopic` related functionalities in Go Function, import 
`github.com/apache/pulsar/pulsar-function-go/log`, and you do not have to use 
the `getLogger()` context object. 
+When you use `logTopic` related functionalities in Go Function, import 
`github.com/apache/pulsar/pulsar-function-go/logutil`, and you do not have to 
use the `getLogger()` context object. 
 
 <!--END_DOCUSAURUS_CODE_TABS-->
 

Reply via email to