wolfstudy commented on a change in pull request #4008: [go function]support log 
topic for go function
URL: https://github.com/apache/pulsar/pull/4008#discussion_r273603876
 
 

 ##########
 File path: pulsar-function-go/pf/instance.go
 ##########
 @@ -259,6 +268,39 @@ func getIdleTimeout(timeoutMilliSecond time.Duration) 
time.Duration {
        return timeoutMilliSecond
 }
 
+func (gi *goInstance) setupLogHandler() error {
+       if gi.context.instanceConf.funcDetails.GetLogTopic() != "" {
+               gi.context.logAppender = NewLogAppender(
+                       gi.client,                                         
//pulsar client
+                       gi.context.instanceConf.funcDetails.GetLogTopic(), 
//log topic
+                       
getDefaultSubscriptionName(gi.context.instanceConf.funcDetails.Tenant, //fqn
+                               gi.context.instanceConf.funcDetails.Namespace,
+                               gi.context.instanceConf.funcDetails.Name),
+               )
+               return gi.context.logAppender.Start()
+       }
+       return nil
+}
+
+func (gi *goInstance) addLogTopicHandler() {
+       if gi.context.logAppender == nil {
+               panic("please init logAppender")
+       }
+
+       for _, logByte := range log.StrEntry {
 
 Review comment:
   OK, there is a bad place in this pr. About the processing logic of 
[]StrEntry, I should push it in this pull request, so the whole code logic may 
be relatively clear.
   
   The specific processing logic is as follows:
   
   in pulsar-function-go/log/log.go
   ```
   var StrEntry []string
   
   func (hook *contextHook) Fire(entry *log.Entry) error {
           ...
           //handler log appender
        strEntry, err := entry.String()
        if err != nil {
                fmt.Fprintf(os.Stderr, "Unable to read entry, %v", err)
                return err
        }
        StrEntry = append(StrEntry, strEntry)
        return nil
   }
   ```
   
   In go function, we used used is [logrus](https://github.com/sirupsen/logrus) 
as log lib. He has a powerful function **hook**. Users can implement hooks 
themselves to ensure that each time the log is written, the Fire() method in 
the hook is called. With this feature,  i put the logs I need to write every 
time into []StrEntry, so that in our appender, we can get the data we want from 
this []StrEntry, and then send it to the producer's msg payload for 
corresponding processing.
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to