From XennisWiki
Jump to: navigation, search

Stackdriver is the logging solution of the Google Cloud Platform.

Go library

Further information: Stackdriver Logging Client Libraries


Create a client

ctx := context.Background()
proj := os.Getenv("GOOGLE_CLOUD_PROJECT")
if proj == "" {
	log.Fatalf("GOOGLE_CLOUD_PROJECT environment variable must be set")
client, err := logging.NewClient(ctx, proj)
if err != nil {
	log.Fatalf("Could not create logger: %v", err)
defer client.Close()

Create a logger and log

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

labels := map[string]string{"my-key": "my-value"}
logger.Log(logging.Entry{Payload: "my-text", Labels: labels})

Create a standard logger instead

logger := client.Logger(logName).StandardLogger(logging.Info)

See also

External links