简体   繁体   English

为什么 Google Logging 客户端库不在 Google 云功能中记录?

[英]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.

相关问题 使用 Google Cloud go 库进行日志记录时出现问题 - Problems using the Google Cloud go library for logging 记录到 stderr 和 stdout golang Google Cloud Platform - Logging to stderr and stdout golang Google Cloud Platform 使用 Go 在 Google Container/Compute Engine 中登录到 Google Cloud - Logging to the Google Cloud in Google Container/Compute Engine with Go 有没有一种方法可以添加要通过Google Cloud语音记录存储在Google Cloud上的音频文件以及与业务相关的特定元数据? - Is there a way to add business specific metadata to be stored along with audio file stored on google cloud via google cloud speech logging? 如何配置 cloud.google.com/go/logging 看起来像写入标准输出的日志? - How to configure cloud.google.com/go/logging to look like logs written to stdout? 如何创建与请求日志的跟踪 ID 相关的 Google Cloud Logging 条目? - How to create Google Cloud Logging entries that are correlated with the request log's trace ID? 使用 Go 的 Google 云客户端库时出错:未知凭据类型:“impersonated_service_account”? - Getting error using Google cloud client libraries for Go: unknown credential type: "impersonated_service_account"? 使用 Golang 的 Google Cloud Functions 工作流 - Workflow for Google Cloud Functions with Golang HTTP 中间件和 Google Cloud Functions - HTTP Middleware and Google Cloud Functions 在 Golang 中安排 Google Cloud 功能? - Schedule Google Cloud Functions in Golang?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM