1## Stackdriver Logging [![GoDoc](https://godoc.org/cloud.google.com/go/logging?status.svg)](https://godoc.org/cloud.google.com/go/logging) 2 3- [About Stackdriver Logging](https://cloud.google.com/logging/) 4- [API documentation](https://cloud.google.com/logging/docs) 5- [Go client documentation](https://godoc.org/cloud.google.com/go/logging) 6- [Complete sample programs](https://github.com/GoogleCloudPlatform/golang-samples/tree/master/logging) 7 8### Example Usage 9 10First create a `logging.Client` to use throughout your application: 11[snip]:# (logging-1) 12```go 13ctx := context.Background() 14client, err := logging.NewClient(ctx, "my-project") 15if err != nil { 16 // TODO: Handle error. 17} 18``` 19 20Usually, you'll want to add log entries to a buffer to be periodically flushed 21(automatically and asynchronously) to the Stackdriver Logging service. 22[snip]:# (logging-2) 23```go 24logger := client.Logger("my-log") 25logger.Log(logging.Entry{Payload: "something happened!"}) 26``` 27 28Close your client before your program exits, to flush any buffered log entries. 29[snip]:# (logging-3) 30```go 31err = client.Close() 32if err != nil { 33 // TODO: Handle error. 34} 35```