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?
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