Logging to the Google Cloud in Google Container/Compute Engine with Go

吃可爱长大的小学妹 提交于 2019-12-01 03:24:37

问题


I have a GKE application with 20 nodes running Go. I would like to consolidate all the logs to view in the Google Developers Console log viewer, but I am having 2 problems. I can't get severity filtering, and each newline in my log message starts a new log entry in the viewer (problematic with newlines in the log).

I have the google-fluent-d setup so all stdout gets logged in the cloud, and I have made use of log.Lshortfile, call depth and log.Logger.Output to get filename and line number from the "log" library.

I've looked at this library: "google.golang.org/cloud/logging" but I am having trouble getting it to work.

Is there a library somewhere or an example of the best way to write logs in GKE and GCE?


回答1:


There are a couple things you can do depending on how ambitious you're feeling.

The easiest option would likely be to switch your logging format to be JSON. The google-fluentd agent will automatically parse the JSON for you, exporting each message's structured data to the cloud logging API. It will automatically grab severity information if a severity field is in the JSON, and using JSON can keep it from breaking on (escaped) newlines in your messages.

The tougher (but more flexible) option would be to get the client library that you found working. I'm not sure whether it's the same as the one you linked to, but I believe this is the most recent one. If you can give more context about the problems you had, I can help or wrangle someone from the cloud logging team to help.



来源:https://stackoverflow.com/questions/35582153/logging-to-the-google-cloud-in-google-container-compute-engine-with-go

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!