top

Package logging contains a Stackdriver Logging client suitable for writing logs. For reading logs, and working with sinks, metrics and monitored resources, see package cloud.google.com/go/logging/logadmin.

This client uses Logging API v2. See https://cloud.google.com/logging/docs/api/v2/ for an introduction to the API.

This package is experimental and subject to API changes.

Creating a Client

Use a Client to interact with the Stackdriver Logging API.

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

Basic Usage

For most use-cases, you'll want to add log entries to a buffer to be periodically flushed (automatically and asynchronously) to the Stackdriver Logging service.

// Initialize a logger
lg := client.Logger("my-log")

// Add entry to log buffer
lg.Log(logging.Entry{Payload: "something happened!"})

Closing your Client

You should call Client.Close before your program exits to flush any buffered log entries to the Stackdriver Logging service.

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

Synchronous Logging

For critical errors, you may want to send your log entries immediately. LogSync is slow and will block until the log entry has been sent, so it is not recommended for basic use.

lg.LogSync(ctx, logging.Entry{Payload: "ALERT! Something critical happened!"})

The Standard Logger Interface

You may want use a standard log.Logger in your program.

// stdlg implements log.Logger
stdlg := lg.StandardLogger(logging.Info)
stdlg.Println("some info")

Log Levels

An Entry may have one of a number of severity levels associated with it.

logging.Entry{
	Payload: "something terrible happened!",
	Severity: logging.Critical,
}

Imported by 77 package(s)

  1. camlistore.org/pkg/deploy/gce
  2. camlistore.org/pkg/osutil/gce
  3. camlistore.org/server/camlistored
  4. camlistore.org/server/camnetdns
  5. camlistore.org/website
  6. cloud.google.com/go/errors
  7. cloud.google.com/go/logging/logadmin
  8. github.com/BrickXu/docker/daemon/logger/gcplogs
  9. github.com/CaptainCodeman/gce-cache-cluster
  10. github.com/DieterReuter/docker/daemon/logger/gcplogs
  11. github.com/FiloSottile/camlistore/pkg/deploy/gce
  12. github.com/FiloSottile/camlistore/pkg/osutil/gce
  13. github.com/FiloSottile/camlistore/server/camlistored
  14. github.com/FiloSottile/camlistore/server/camnetdns
  15. github.com/FiloSottile/camlistore/website
  16. github.com/GoogleCloudPlatform/compute-image-tools/daisy
  17. github.com/GoogleCloudPlatform/gcloud-golang/errors
  18. github.com/Nitecon/gcloud-golang/errors
  19. github.com/SUSE/docker/daemon/logger/gcplogs
  20. github.com/StratexIO/gclog
  21. github.com/WIZARD-CXY/docker/daemon/logger/gcplogs
  22. github.com/WeiZhang555/docker/daemon/logger/gcplogs
  23. github.com/antihax/gddo/gddo-server
  24. github.com/aseure/gcloud-golang/errors
  25. github.com/boynux/docker/daemon/logger/gcplogs
  26. github.com/camlistore/camlistore/pkg/deploy/gce
  27. github.com/camlistore/camlistore/pkg/osutil/gce
  28. github.com/camlistore/camlistore/server/camlistored
  29. github.com/campoy/justforfunc/15-logpipe
  30. github.com/christopherobin/docker/daemon/logger/gcplogs
  31. github.com/cloudfoundry-community/stackdriver-tools/src/stackdriver-nozzle/messages
  32. github.com/cloudfoundry-community/stackdriver-tools/src/stackdriver-nozzle/nozzle
  33. github.com/cloudfoundry-community/stackdriver-tools/src/stackdriver-nozzle/stackdriver
  34. github.com/davars/gae/impl/cloud
  35. github.com/dgageot/docker/daemon/logger/gcplogs
  36. github.com/dqminh/docker/daemon/logger/gcplogs
  37. github.com/flavio/docker/daemon/logger/gcplogs
  38. github.com/garyburd/gddo/gddo-server
  39. github.com/garyburd/gopkgdoc/gddo-server
  40. github.com/gbbr/gddo/gddo-server
  41. github.com/golang/gddo/gddo-server
  42. github.com/google/cloudprober/logger
  43. github.com/gysan/docker/daemon/logger/gcplogs
  44. github.com/istio/mixer/adapter/stackdriver/log
  45. github.com/istio/old_mixer_repo/adapter/stackdriver/log
  46. github.com/jba/google-cloud-go/errors
  47. github.com/jen20/docker/daemon/logger/gcplogs
  48. github.com/jessfraz/docker/daemon/logger/gcplogs
  49. github.com/jmhodges/howsmyssl
  50. github.com/jonstaryuk/gcloudzap
  51. github.com/jonstaryuk/logwatch/cmd
  52. github.com/jonstaryuk/logwatch/gcp
  53. github.com/lai-nam/docker/daemon/logger/gcplogs
  54. github.com/maliceio/engine/daemon/logger/gcplogs
  55. github.com/mpl/camlistore/pkg/deploy/gce
  56. github.com/mpl/camlistore/pkg/osutil/gce
  57. github.com/mpl/camlistore/server/camlistored
  58. github.com/mpl/camlistore/server/camnetdns
  59. github.com/nalind/docker/daemon/logger/gcplogs
  60. github.com/nathany/gddo/gddo-server
  61. github.com/nictuku/docker/daemon/logger/gcplogs
  62. github.com/perkeep/perkeep/server/camnetdns
  63. github.com/quinnjr/cinder/handlers/google
  64. github.com/recursionpharma/stackrus
  65. github.com/redsift/go-zap-stackdriver
  66. github.com/rhatdan/moby/daemon/logger/gcplogs
  67. github.com/rhatdan/moby1/daemon/logger/gcplogs
  68. github.com/savaki/stackdriver
  69. github.com/sdurrheimer/docker/daemon/logger/gcplogs
  70. github.com/shishir-a412ed/docker/daemon/logger/gcplogs
  71. github.com/soulshake/docker/daemon/logger/gcplogs
  72. github.com/stratexio/gclog
  73. github.com/tianon/docker/daemon/logger/gcplogs
  74. github.com/tiborvass/docker/daemon/logger/gcplogs
  75. github.com/tortuoise/gcloud-golang/errors
  76. github.com/unclejack/moby/daemon/logger/gcplogs
  77. github.com/yosifkit/docker/daemon/logger/gcplogs

Imported only in test by 1 package(s)

  1. github.com/GoogleCloudPlatform/gcloud-golang/logging

Imports 12 package(s)

  1. cloud.google.com/go/logging/apiv2
  2. github.com/golang/protobuf/proto
  3. google.golang.org/api/support/bundler
  4. google.golang.org/genproto/googleapis/api/monitoredres
  5. google.golang.org/genproto/googleapis/logging/v2
  6. github.com/golang/protobuf/ptypes/timestamp
  7. google.golang.org/api/option
  8. github.com/golang/protobuf/ptypes
  9. github.com/golang/protobuf/ptypes/struct
  10. golang.org/x/net/context
  11. google.golang.org/genproto/googleapis/logging/type
  12. cloud.google.com/go/logging/internal

Test imports 7 package(s)

  1. github.com/golang/protobuf/ptypes/duration
  2. cloud.google.com/go/logging/internal/testing
  3. google.golang.org/grpc
  4. cloud.google.com/go/internal/testutil
  5. cloud.google.com/go/logging/logadmin
  6. golang.org/x/oauth2
  7. google.golang.org/api/iterator