Log Trigger LTS¶
You can write FunctionGraph functions to process logs subscribed to Cloud Log Service. When Cloud Log Service collects subscribed logs, you can call FunctionGraph functions by passing the collected logs as parameters (LTS sample events). FunctionGraph function code can be customized, analyzed, or loaded into other systems. For the use of LTS log triggers, please refer to Using a LTS Trigger.
Example LTS Event¶
{
"lts": {
"data": "=="
}
}
Parameter description¶
Parameter |
Type |
Example Value |
Description |
|---|---|---|---|
data |
String |
Reference examples |
Base64 encoded data |
Example¶
package main
import (
"encoding/json"
"fmt"
"github.com/opentelekomcloud-community/otc-functiongraph-go-runtime/go-runtime/events/lts"
"github.com/opentelekomcloud-community/otc-functiongraph-go-runtime/go-runtime/go-api/context"
"github.com/opentelekomcloud-community/otc-functiongraph-go-runtime/go-runtime/pkg/runtime"
)
// Example for Log Tank Service handler
func LtsTest(payload []byte, ctx context.RuntimeContext) (interface{}, error) {
var ltsEvent lts.LTSTriggerEvent
err := json.Unmarshal(payload, <sEvent)
if err != nil {
fmt.Println("Unmarshal failed")
return "invalid data", err
}
ctx.GetLogger().Logf("payload:%s", ltsEvent.String())
return "ok", nil
}
func main() {
runtime.Register(LtsTest)
}