tree: fedb9733e31bc8000d65a6c69efff33d431df2b9 [path history] [tgz]
  2. apiv2/
  3. doc.go
  4. examples_test.go
  5. go.mod
  6. go.sum
  7. go_mod_tidy_hack.go
  8. internal/
  9. logadmin/
  10. logging.go
  11. logging_test.go
  12. logging_unexported_test.go

Stackdriver Logging GoDoc

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 Stackdriver 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.