[英]Why Google Logging client libraries not logging inside Google cloud functions?
I'm trying to implement a google cloud function to test Google Logging client library.我正在尝试实现一个谷歌云功能来测试谷歌日志客户端库。 below is my code下面是我的代码
// Package p contains an HTTP Cloud Function.
package loggingclient
import (
"cloud.google.com/go/logging"
"net/http"
"context"
"fmt"
)
// HelloWorld prints the JSON encoded "message" field in the body
// of the request or "Hello, World!" if there isn't one.
func HelloWorld(w http.ResponseWriter, r *http.Request) {
label := map[string]string{"priority": "High"}
var projectName = "my-project-id"
ctx := context.Background()
client, err := logging.NewClient(ctx, projectName)
if err != nil {
fmt.Printf("client not created: %v", err)
}
lg := client.Logger("MY-LOGGER")
lg.Log(logging.Entry{
Payload: "Hello, This is error!!",
Severity: logging.Error,
Labels: label,
})
client.Close()
}
Here, I'm expecting a log entry with a message:"Hello, This is error!!"在这里,我期待一个带有消息的日志条目:“你好,这是错误!!” and with a lable:"priority": "High" and severirty "ERROR"并带有标签:“优先级”:“高”和严重的“错误”
But actually, when I trigger this Cloud Function, I didn't get any new log entries.但实际上,当我触发这个云函数时,我并没有得到任何新的日志条目。 Therefore don't client logging libraries work inside cloud functions?, How to resolve this?因此,客户端日志库不能在云函数中工作吗?,如何解决这个问题?
Thanks谢谢
It works on cloud functions.它适用于云功能。 I have done the exact same thing in a cloud function before.我之前在云功能中做过完全相同的事情。 You can use google's official documenation with cloud function logging here您可以在此处使用带有云功能日志记录的 google 官方文档
Also ensure that the service account have necessary permissions for logging https://cloud.google.com/logging/docs/access-control还要确保服务帐户具有登录https://cloud.google.com/logging/docs/access-control的必要权限
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.