tree: 856e3d51913aca4dcc9ba1ac7f3d8e48e0869b22 [path history] [tgz]
  1. apiv2/
  2. internal/
  3. jsonlog/
  4. logadmin/
  5. CHANGES.md
  6. doc.go
  7. examples_test.go
  8. go.mod
  9. go.sum
  10. go_mod_tidy_hack.go
  11. logging.go
  12. logging_test.go
  13. logging_unexported_test.go
  14. README.md
  15. resource.go
logging/README.md

Cloud Logging Go Reference

Example Usage

First create a logging.Client to use throughout your application: [snip]:# (logging-1)

ctx := context.Background()
client, err := logging.NewClient(ctx, "my-project")
if err != nil {
   // TODO: Handle error.
}

Usually, you'll want to add log entries to a buffer to be periodically flushed (automatically and asynchronously) to the Cloud Logging service. [snip]:# (logging-2)

logger := client.Logger("my-log")
logger.Log(logging.Entry{Payload: "something happened!"})

Close your client before your program exits, to flush any buffered log entries. [snip]:# (logging-3)

err = client.Close()
if err != nil {
   // TODO: Handle error.
}