Google Stackdriver日志记录在Google Cloud Shell和GKE

时间:2017-12-11 16:39:29

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

我为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中手动运行容器时,我都会“创建日志客户端”。 但我得到“开始服务!”只有在我自己的机器上运行容器时。

1 个答案:

答案 0 :(得分: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云端控制台上的日志名称获取所有日志,而在CLI上则可以...

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