1## Cloud Logging [![Go Reference](https://pkg.go.dev/badge/cloud.google.com/go/logging.svg)](https://pkg.go.dev/cloud.google.com/go/logging) 2 3- [About Cloud Logging](https://cloud.google.com/logging/) 4- [API documentation](https://cloud.google.com/logging/docs) 5- [Go client documentation](https://pkg.go.dev/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 13```go 14ctx := context.Background() 15client, err := logging.NewClient(ctx, "my-project") 16if err != nil { 17 // TODO: Handle error. 18} 19``` 20 21Usually, you'll want to add log entries to a buffer to be periodically flushed 22(automatically and asynchronously) to the Cloud Logging service. 23[snip]:# (logging-2) 24 25```go 26logger := client.Logger("my-log") 27logger.Log(logging.Entry{Payload: "something happened!"}) 28``` 29 30Close your client before your program exits, to flush any buffered log entries. 31[snip]:# (logging-3) 32 33```go 34err = client.Close() 35if err != nil { 36 // TODO: Handle error. 37} 38``` 39