【问题标题】:Google Stackdriver Logging doesn't work in Google Cloud Shell nor GKEGoogle Stackdriver Logging 不适用于 Google Cloud Shell 或 GKE
【发布时间】:2018-05-25 05:47:25
【问题描述】:

我已经为 GKE 构建了一个 docker 镜像,并且想使用 Google Stackdriver Logging。

目前我只是想在服务启动时记录Service started

虽然在我的主机上运行容器运行良好(在 Google Cloud Console > Logs Viewer > Global,我可以看到 Service started 在预期时),但在 Google Cloud Shell 上以完全相同的方式运行容器却不行记录任何东西。部署到 GKE 的行为完全相同,没有错误,但我找不到应该创建的日志。

以下是我的集群的范围: cloud-platform,compute-rw,datastore,default,storage-full,logging-write,service-control,service-management.

请注意,日志客户端已成功创建:

client, err := logging.NewClient(ctx, projectID)

if err != nil {
    log.Fatalf("Failed to create the logging client: %v", err)
} else {
    fmt.Println("Logging client created")
}

app.Logger = client.Logger(logName)

text := "Started service !"

app.Logger.Log(logging.Entry{
    Payload: text,
})

每次在集群日志中或在 Google Cloud Shell 中手动运行容器时,我都会收到“已创建日志记录客户端”。 但我得到“开始服务!”仅在我自己的机器上运行容器时。

【问题讨论】:

    标签: google-cloud-platform google-cloud-stackdriver google-cloud-shell google-kubernetes-engine


    【解决方案1】:

    我运行了gcloud logging 命令:

    gcloud logging read "logName=projects/${PROJECT_ID}/logs/${LOG_NAME}"
    

    我发现type: gce_instance 而不是预期的type: global

    感谢https://stackoverflow.com/a/45085569/7046455 我在GCE VM Instance 下找到了我的日志。

    不能在 Google Cloud Console 上简单地按日志名称获取所有日志,这很令人惊讶,而在 CLI 上却可以...

    编辑:这些实际上是来自 Google Cloud Shell 的日志,而不是来自我的容器!我仍然没有发现为什么我的日志没有在我的集群中创建......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-27
      • 2021-05-27
      • 1970-01-01
      • 1970-01-01
      • 2021-01-22
      • 1970-01-01
      • 1970-01-01
      • 2021-05-28
      相关资源
      最近更新 更多